1. WordPress Snippets

How to exclude categories from the WordPress category widget

if you need to exclude some categories from the WordPress category widget which finds it as a default WordPress widget you can do it in just one minute using this code snippet.

Steps to exclude categories from the WordPress category widget:

  1. Open the WordPress admin panel then go to Appearance > Theme Editor
  2. Open theme functions.php file, if you work localhost open the same file using any code editor IDE
  3. Add the following code at the bottom of the file.
  4. Save the changes.
function zytheme_exclude_widget_categories($args){

    $exclude = "1,4,8,57,80"; //Add your category ids here
    $args["exclude"] = $exclude;
    return $args;
}
add_filter("widget_categories_args","zytheme_exclude_widget_categories"); 

Did you find the WordPress snippets in this article helpful? Share it with your friends and if you have any questions and want to ask us about it, please don’t hesitate to add comments.

Comments to: How to exclude categories from the WordPress category widget

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