0

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)?

0

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:

if($nextcustomfield){
    echo '<a href="'.$nextcustomfield.'">NEXT</a>';
}else{
    NORMAL NEXT LINK CODE
}

Your Answer

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

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