Here we will see an example on how to exclude category from WordPress category widget. We will not use any plugin to exclude categories from WordPress category widget.

For a simple change it is not recommended to use plugin because using plugin your site’s overall page speed may decrease. As a side effect your site’s performance will hamper.

WordPress provides a default category widget and using this category widget you can display categories as a list or as a dropdown.

So we will write a simple code snippets to exclude category or categories from both list and dropdown.

The code snippets which we will show here, you have to add functions.php file. If you have child theme then you need to add to child theme’s functions.php file. If this file doesn’t exist then you have to create under child theme.

Code Snippets

Let’s see the code snippets below:

function exclude_category_widget($args) {
	$excludes = "840, 841"; // Category ids to be excluded
	$args["exclude"] = $excludes;
	return $args;


We have defined a function exclude_category_widget() and this function will remove the category or categories from list or dropdown.

You need to pass multiple category ids separated by comma to exclude multiple categories or if you want to exclude single category then you need to pass only single category.

We have added the above function to add_filter() function and first line is used to remove from category list and second line removes from category dropdown.

make sure you put the above code inside <?php ?> tag. The end tag ?> is not required but the start tag <?php must be present.

How to find category id?

Login to your WordPress site’s admin dashboard and go to Posts -> Categories. Now mouse over on a particular category name. Then you will see, for example, tag_ID=840. This tag_ID is the category id.

Thanks for reading.

Leave a Reply

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