WordPress How-To: Exclude a Category from the “Previous/Next” Links

How-to exclude certain categories from the “Previous/Next” links in WordPress 4.1.

There are instances where you may have a category that you do not want the default WordPress “Previous/Next” links to display. The following short code sample will quickly eliminate the listed categories from displaying.

WordPress suggests that you place the following code in your theme’s functions.php file. This is not an ideal location because you will have to re-edit the file every time you update or change your theme. One suggestion is to use a plug-in like Add Actions And Filters that will allow you to maintain your action and filter edits separately from any themes. Alternatively, if you are developing your own plug-in, place the code in your plugin’s root file.

Notice on the highlighted $exclude assignment line, I have the values "9,10". Place your own category ID(s) to exclude here instead.

To exclude certain categories’ from displaying in the “Categories Widget”, check out WordPress How-To: Exclude a Category from the “Categories Widget”.

To exclude certain categories’ from displaying in the “Archives Widget”, check out WordPress How-To: Exclude a Category from the “Archives Widget”.

To exclude certain categories’ from displaying in the “Recent Posts Widget”, check out WordPress How-To: Exclude Posts from the “Recent Posts Widget” by Category.

To exclude certain categories’ posts from displaying check out WordPress How-To: Exclude Posts by Category.

Posted in WordPress Tagged with: , , , , ,
3 comments on “WordPress How-To: Exclude a Category from the “Previous/Next” Links
  1. alexey says:

    How do categories and subcategories?

  2. alexey says:

    … and for single post from exclude certain categories (and its subcategories) show the ‚ÄúPrevious/Next from only from this exclude certain categories (and its subcategories)

  3. alexey says:

    How to cancel the filter action for posts from excluded categories?

Leave a Reply

Your email address will not be published. Required fields are marked *

*