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

3
  • Code you are using? Commented Aug 5, 2018 at 11:34
  • @Castiblanco, currently I am using script tag in each post to set next and prev variables. And after page load I am updating the next and prev DOM elements with the link and title. Commented Aug 5, 2018 at 11:35
  • This post can answer to your question: wordpress.stackexchange.com/questions/139453/… Commented Aug 5, 2018 at 12:39

1 Answer 1

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 and acknowledge you have read our privacy policy.

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