Archived topic
Store the referrer
3 replies · Started by Tushar on January 21, 2023
I have to pass in the web referrer to my pages. How do I store this when a user comes to my site and then pass the value to a form.
Hi there,
WordPress has the wp_get_referer() function you can use:
https://developer.wordpress.org/reference/functions/wp_get_referer/
Thanks, I was aware of this.
The question I had was how can I use it in one of the generatepress pages
The Theme has little to do with it.
You can store the referrer in many ways. For example:
add_action('wp', function(){
// conditional logic - if referrer is different to current request URL
// if page ID is 99
if ( wp_get_referer() && is_page(99) ) {
global $my_variable;
$my_variable = wp_get_referer();
}
});
change the 99 to match the page you want to get the referrer on.
And i the referrer URL is different to the current request then it will store it in the global $my_variable
You can then access that variable from your form.