WordPress: How to Remove a Category From Menu Lists

by | Dec 18, 2014 | Wordpress | 0 comments

The list of categories that is most often displayed in WordPress comes from the Categories widget (Appearance > Widgets).  Unfortunately, the widget does not allow you to drop a particular category or categories from the list.  This is easily done by editing the functions.php file found in your child theme in the wp-content/themes directory.  If the child theme does not have a functions.php file, copy it from the main theme and put it in the child theme’s directory.  To drop a category from the list add this:

/*The following function excludes a category from the right-side menu widget. */

function exclude_widget_categories($args){

$exclude = “140”; // The IDs of the excluding categories

$args[“exclude”] = $exclude;

return $args;

}

add_filter(“widget_categories_args”,”exclude_widget_categories”);

to the functions.php file betfore the end of php tag (?>). The example excludes category 140.  To determine the category number go to Posts > Categories and open the category you want for editing.  You will see something like “tag_ID=140” in the URL for that page.  That’s the category number.

If you want to exclude several categories, separate the numbers with a comma, e.g. “1,5,140”