• Resolved balaji0709

    (@balaji0709)


    Hi,

    How can I get the URL of the previous page in a custom template file in WordPress?

    We tried using $_SERVER['HTTP_REFERER'], but it doesn’t work correctly when the WP Rocket plugin is activated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Devin Maeztri

    (@devinmaeztri)

    Hi, it seems the issue is related to the plugin. Caching can affect how server headers and HTTP requests are handled, potentially causing HTTP_REFERER to be inaccurate or unavailable. I suggest reaching out to their support team for help. https://wp-rocket.me/support/

    Thread Starter balaji0709

    (@balaji0709)

    @devinmaeztri Hi

    Thanks. Are there any other options to retrieve the previous page URL?

    catacaustic

    (@catacaustic)

    Do you need the actual URL, or do you just want to have a “Back” link?

    If you want the actual URL, the various PHP variables in $_SERVER are what you’ll have to work with. Alternatively you could always set a cookie with the current URL and read that in when the page loads before you update it to the current page URL.

    If you just want a “Back” link, a JavaScript option is about the best way to do it.

    <a href="javascript:history.back();">[Go Back]</a>
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.