Is it possible to force previous/next navigation to browse through the posts (back and forth) that are only inside the same category (and to exclude other categories)?

2 Answers 2


The functions accept an $in_same_cat argument, the default value of which is false. Just set that to true.

previous_post_link($format, $link, true);
next_post_link($format, $link, true);
  • Thanks! My wife asked for this and your answer made it a 10 minutes job to customize my child theme!
    – ajh158
    Commented Sep 5, 2014 at 2:10

You can use the following code in single.php loop to display nex/pre links in same category


get_template_part( 'content', get_post_format() );

 // Previous/next post navigation.
previous_post_link('%link', 'Before', true );
next_post_link( '%link', 'Next', true );


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.