How to exclude or hide categories from category widget in WordPress sidebar?

WordPress comes with a built-in category widget which allows you to list your categories in the sidebar. This feature is very helpful for people to navigate your blog/website.

Useful Read : Hide or remove welcome panel from WordPress dashboard

However, you may not want to list all of your categories in this widget. But, the problem is this widget doesn’t have an option to exclude specific categories. You can easily fix this issue by inserting a small amount of code in your functions.php file.

To exclude or hide specific categories from default category widget use the following code:

//Hide categories from WordPress category widget
function exclude_widget_categories($args){
    $exclude = "1,4,8,57,80";
    $args["exclude"] = $exclude;
    return $args;
}
add_filter("widget_categories_args","exclude_widget_categories");

Note: Replace “1,4,8,57,80” with your own category IDs and paste the code in your functions.php file.

 

9 Comments

  1. I used this with modified “widget_categories_dropdown_args” but the categories 2111-214 still showing. What’s wrong with my code?

    function exclude_widget_categories($args){
    $exclude = “211,212,213,214”;
    $args[“exclude”] = $exclude;
    return $args;
    }
    add_filter(“widget_categories_dropdown_args”,”exclude_widget_categories”);

    Reply

Leave a Comment.