When building a WordPress site, there are a lot of different bits and bobs to put in place before the theme, and your site, is up and running. Of course, one of the most important parts of your site are your widgets, as they help to provide useful links and sections down your sidebars for any new visitors. Of course, one of the most common, especially if you’re a site with blog or journalistic content, is going to be your categories list.

So, say you’ve got some categories you use privately so you know which posts you used to talk about your IMAP email server, and which ones you used to talk about the times you play Foxy bingo (www.foxybingo.com). If you don’t want these categories to show up, but you do want “everyday”, “going out”, “thoughts on politics” and such to show without costing you the entire widget, there is a solution. Read on to learn how to sort this issue.

To exclude categories from WordPress default widget “Categories”, add this code in the file functions.php of the using theme:

<?php
function exclude_widget_categories($args){
  $exclude = "3,6,18"; // The IDs of the excluding categories
  $args["exclude"] = $exclude;
  return $args;
}
add_filter("widget_categories_args","exclude_widget_categories");
?>

The method to exclude the categories from the widget is better, as it is in the file of the theme and it will work after the updating WordPress versions.

After the widget, time to deal with your hosting. Learn more about one of the best wordpress host providers at InMotionHosting.com.

Share

14 Comments on Exclude categories from the default widget “Categories”

  1. Anders says:

    I have just got a blog and use about 50 different plugins. Thank you very much for your plugin. It complete my website

  2. Patryk says:

    This is it!! Thanks

  3. Hendrik says:

    Holy shit! Thanks a bunch! I was looking exactly for something like this and even started to edit core files and your solution just does it…

    Thanks again!

  4. Muhammed says:

    Pure awesomeness. thanks a mil

  5. sierra says:

    Wow this does it! Hiding categories was making that category’s RSS feed path show up as “Page not found” until I found your solution. Thanks a lot!

  6. Alex says:

    Great tweak! Saved me loads of time and hassle, and was easy to implement.

  7. I am proud to assist you!!! :)

    Thanks.

  8. Mush says:

    Apres Rubo jan, hpartanum em qezanov, amenaxelaci mardik petqa hayer@ linen misht!!!))

    Ruben you are Great!

  9. As a WordPress beginner who doesn’t really understand PHP, this post saved me a ton of work and frustration. It should be shared everywhere. You’re awesome, thanks 😀

  10. iSTYLE360 says:

    Thank you so much for such a great trick.. i have been looking for it from days..

  11. Pearl says:

    May I ask where in functions.php should I place this.

    I have the most updated version 3.3.2.

  12. Latro666 says:

    Great idea, how do you ensure it updates the post count next to the category if you have that turned on though?

  13. ED says:

    It works!
    I recently help a customer to switch their sites to wordpress:)
    Thanks so much!

  14. ravi says:

    thank ……great idea but how can i exclude all category of parent category …..

Leave a Reply

Info