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
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>
-
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.– AlexCommented Jun 17, 2022 at 12:39