Site logo

[Support request] Store the referrer

Home Forums Support [Support request] Store the referrer

Home Forums Support Store the referrer

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2503670
    Tushar

    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.

    #2503792
    David
    Staff
    Customer Support

    Hi there,

    WordPress has the wp_get_referer() function you can use:

    https://developer.wordpress.org/reference/functions/wp_get_referer/

    #2503846
    Tushar

    Thanks, I was aware of this.

    The question I had was how can I use it in one of the generatepress pages

    #2504062
    David
    Staff
    Customer Support

    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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.