WordPress How-To: Exclude a Category from the “Archives Widget”

How-to exclude certain categories from displaying in the “Archives Widget” in WordPress 4.1.

There are instances where you may have a category that you do not want the default WordPress “Archive Widget” to display, tally, or count. The following short code sample will quickly eliminate the listed categories from being included in the “Archives Widget”‘s tally.

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.

Once again, this will only exclude one or more categories from being counted in the default WordPress “Archive Widget”.
If a user clicks on an archived month’s link, the excluded categories post(s) WILL show up amongst the other posts.

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 “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.

To exclude certain categories’ posts from displaying in posts’ “Previous/Next” links check out WordPress How-To: Exclude a Category from the “Previous/Next” Links.

Posted in WordPress Tagged with: , , , ,
2 comments on “WordPress How-To: Exclude a Category from the “Archives Widget”
  1. Valeriy says:

    Incorrect display number of post in monthly archive

    • GrokDD says:

      Valeriy,

      Thank you for trying out the code sample above. I’ve tried recreate the error you are perceiving, to no avail. As I have noted in the above article,

      If a user clicks on an archived month’s link, the excluded categories post(s) WILL show up amongst the other posts.

      Meaning, extra measures are needed to ensure that if a user clicks on the monthly archive link, the excluded posts do not show up in the list of post titles and excerpts. To accomplish this, follow the sister tutorial WordPress How-To: Exclude Posts by Category.

      Following these two tutorials, on my demo site, I achieve the same number in the archive widget, as the number of posts displayed on the monthly archive page. To the best of my knowledge, this approach works.

      If you are still experiencing inconsistencies, share your code, and let’s figure it out together.

      Thanks again for stopping by and reading my posts!

Leave a Reply

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

*