I’m trying to hide a large amount of categories from my category widget. I’ve tried a few plugins but none of them seem to want to let me use the dropdown option. I looked into the widget_categories_args hook and that seems to be what I want but I can’t get it to work.

Anyways here’s my code

function widget_categories_args_filter( $cat_args ) {
$exclude_arr = array( 57,61,63,56,55,62,52,53,54,67,65 );

if( isset( $cat_args['exclude'] ) && !empty( $cat_args['exclude'] ) )
    $exclude_arr = array_unique( array_merge( explode( ',', $cat_args['exclude'] ), $exclude_arr ) );
$cat_args['exclude'] = implode( ',', $exclude_arr );
return $cat_args;
}

add_filter( 'widget_categories_args', 'widget_categories_args_filter', 10, 1 );

I Took that from here: https://codex.wordpress.org/Plugin_API/Filter_Reference/widget_categories_args

I’m putting this in my theme’s functions.php. That shouldn’t matter even though the function is set for plugins, right?

5

I know this post is pretty old, but because I came across the same issue and this post came up higher than one with a solution, I figured I’d add this, which worked for me.

Source: http://coffeecupweb.com/how-to-exclude-or-hide-categories-from-category-widget-in-wordpress-sidebar/

//Hide categories from WordPress category widget
function exclude_widget_categories($args){
    $exclude = "1,4,8,57,80";
    $args["exclude"] = $exclude;
    return $args;
}
add_filter("widget_categories_args","exclude_widget_categories");

Leave a Reply

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