0

in my single.php i want to add a "back-to-overview"-button which leads to the posts archive. But if my post is located in, lets say, page 7 of the archive, i want my back-button link to this page 7. How can i find out, on which page my post is located? I think i could achieve this by querying all posts and then calculate the position, but - as wordpress has a function or hook for nearly everything - i wonder if there is better (and more performant) way.

1 Answer 1

0

There's no built-in function for what you're after - plus have you also considered what if a user visited your post from a date-based or category archive? You might find using the HTTP referer is more suitable:

<a href="<?= esc_url( wp_get_referer() ?: home_url() ) ?>">Back to overview</a>
1
  • Thanks, good to know that there is no built-in function. I will think about another solution. I think the referer is no option, because you can also come from a prev/next post link or directly from a search engine.
    – Alex
    Commented Jun 17, 2022 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.