# Exclude Categories From the Categories Widget

> Hides chosen categories from the classic Categories widget list or dropdown.

- Type: PHP
- Runs: Run everywhere
- Category: [Widgets](https://wpide.com/library/category/widgets/)
- Tags: widgets, categories
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/categories-widget-exclude/

## Code

```php
$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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Exclude Categories From the Categories Widget" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
