• Resolved Tetra84

    (@tetra84)


    Hi,

    Hoping someone can help, I’m trying to separate blog posts from press releases, but they’re all categories. I don’t want to have my ‘Press releases’ show up in the widgets on the blog page. I found this that I thought should help, but it was somewhat old, and didn’t seem to work for me.

    What I tried:
    2020-09-22_16-55-45

    https://wordpress.stackexchange.com/questions/192051/hide-specific-categories-from-category-widget

    Does anyone have an updated guide in hiding specific categories from widgets in 2020? Assume it’d need to be code for the functions.php file and not just CSS.

    Thanks,
    Paul

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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;
    }
    add_filter("widget_categories_args","remove_widget_categories");
    
    /* this removes the categories from the dropdown */
    function remove_widget_dropdown_categories($args) {
    	$exclude = "14"; 
    	$args["exclude"] = $exclude;
    	return $args;
    }
    add_filter("widget_categories_dropdown_args","remove_widget_dropdown_categories");

    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;
    }
    add_filter("widget_categories_dropdown_args","custom_category_widget");

    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.

    Thread Starter Tetra84

    (@tetra84)

    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:
    https://emeryallen.com/blog/

    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.

    2020-09-23_13-43-59

    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;
    }
    add_filter("widget_tag_cloud_args","custom_tags_widget");

    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.

    Thread Starter Tetra84

    (@tetra84)

    @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!

    You’re welcome!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Hiding Categories from Widget’ is closed to new replies.