Is there any way to change the next and previous post links dynamically.

By default the previous post link takes to the previous post. However I want it to link to some different post, that I posted way back in time. Similar with the next post link.

Currently I have manually setting the next and prev post links using javascript. Can I achieve this with Wordpress (PHP)?


1 Answer 1


1) As you need to hide next or prev link you should output both.

2) Then create some meta field in posts. I usually use ACF for it, it is pretty easy. Create 2 custom fields, text input fields for every post, let's say: "Next button URL" and "Prev button URL"

3) And in post.php wrap "previous" and "next" buttons created in #1 with if condition, for example:

    echo '<a href="'.$nextcustomfield.'">NEXT</a>';

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.