WordPress by default has a “Categories” widget to display list of all categories. This widget has options like: display as dropdown, show post counts and show hierarchy. Do you want to remove one or multiple categories from displaying when using this category widget? There is no custom option for such removal but some custom code can do the magic.
Code to remove & exclude specific categories
In your functions.php file add the following code.
In the above code: 3,4 are IDs of categories that should be excluded (not to be displayed). You can add more category IDs separated by comma as per requirement.
When using Category dropdown box
When using the category widget in the form of a drop down box, above code won’t work. You can need to use the following code.
Above, we are just replacing widget_categories_args with widget_categories_dropdown_args in the code.