Exclude Categories From the Categories Widget
Hides chosen categories from the classic Categories widget list or dropdown.
Opens WPIDE on
Code
$wpide_excluded_categories = array( 1 ); // Category IDs to hide.
add_filter( 'widget_categories_args', function ( $args ) use ( $wpide_excluded_categories ) {
$args['exclude'] = $wpide_excluded_categories;
return $args;
} );
add_filter( 'widget_categories_dropdown_args', function ( $args ) use ( $wpide_excluded_categories ) {
$args['exclude'] = $wpide_excluded_categories;
return $args;
} );
Notes
Replace 1 with your category IDs.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.