I use pagination in my index.php and I have many posts per page. Every post have a button to go back to home. The problem is that when I visit a post in a page 5 for example, the button always send me on the first page.

I'm using this: <a href="<?php echo home_url(); ?>">back</a>

Is there a simple way to track the post page position, and use it to go back properly?

  • A quick hack: <a href="<?php echo isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : home_url(); ?>">back</a> – Ivan Shatsky Jul 5 '20 at 8:54
  • javascript:history.back() is another slightly hacky option, just simulates the browser's Back button – mozboz Jul 5 '20 at 16:06
  • @IvanShatsky it works! Thank you so much. – saxx Jul 6 '20 at 6:44
  • @mozbot js works good locally but it is not functional if I land on the posts from outside of my website. – saxx Jul 6 '20 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.