Hiding Categories from Widget | WordPress.org

What you have should work just fine. If you are using the dropdown widget, you’ll need something else.

/* this removes the categories from the list */
function remove_widget_categories($args){
	$exclude = "14";
	$args["exclude"] = $exclude;
	return $args;

/* this removes the categories from the dropdown */
function remove_widget_dropdown_categories($args) {
	$exclude = "14"; 
	$args["exclude"] = $exclude;
	return $args;

Note: replace the “14”with the ID of your “Press releases” category.

Place the code in your functions.php

Hi @tetra84,

Paul, the code you shared works for the default Categories Widget. If you’ve set the Categories Widget to “Display as dropdown,” there’s a slightly different filter you’ll need to use:

// Omit Specific Categories from Category Widget
function custom_category_widget($args) {
	$exclude = "43"; // Category ID/s to be omitted separated by comma/s
	$args["exclude"] = $exclude;
	return $args;

widget_categories_dropdown_args needs to be used rather than widget_categories_args.

If that doesn’t work, there may be a plugin or theme conflict that’s preventing the code from working.

I realized why it probably isn’t working.. i’m using the ‘tag cloud’ widget instead of just the ‘categories’ widget. Does anyone know what the code would be to omit a category from that particular widget?

I guess I was thinking there would be some magic bullet code that would remove a particular category from any widget that shows categories.

my site:

Trying to pull it from the bottom right ‘tag cloud’ and also have new press category posts not show up in the “recent posts” (what’s new) or “popular posts” (what’s trending) too.


Try this code for the tags:

// Omit Specific Items from Tag Widget
function custom_tags_widget($args) {
	$exclude = "43"; // Tag ID/s to be omitted separated by comma/s
	$args["exclude"] = $exclude;
	return $args;

I’m pretty certain that the Nectar widgets are created by your theme or a plugin. You’ll need to contact the developers to find out how to remove whatever you need to remove from those widgets.

@nm1com Thank you! That got rid of my category in the cloud tags widget. You are correct about the other widgets being made for my theme. I’ll reach out to them about those.

Thanks for the help guys!

Source link