WordPress: exclude categories from the categories widget

The default categories widget provided by WordPress includes all the categories of your site. To exclude some categories from the list you need to apply a custom filter using a series of IDs.

Just insert the following code into your functions.php file:


function exclude_widget_categories($args) {
	$exclude = '2,4,6'; // Category IDs
	$args['exclude'] = $exclude;
	return $args;
}
add_filter('widget_categories_args','exclude_widget_categories');

Now the categories with ID 2, 4 and 6 won't appear in the output of the widget.

Back to top