# Drop "Uncategorized" When Another Category Is Chosen

> Removes the default category from a post as soon as it has another category, so posts do not end up filed under both.

- Type: PHP
- Runs: Run everywhere
- Category: [Admin](https://wpide.com/library/category/admin/)
- Tags: admin, categories, cleanup
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/drop-uncategorized-when-other-category/

## Code

```php
add_action( 'set_object_terms', function ( $object_id, $terms, $tt_ids, $taxonomy ) {
    if ( 'category' !== $taxonomy || count( $tt_ids ) < 2 ) {
        return;
    }

    $default = (int) get_option( 'default_category' );
    $term    = get_term( $default, 'category' );

    if ( $term && ! is_wp_error( $term ) && in_array( (int) $term->term_taxonomy_id, array_map( 'intval', $tt_ids ), true ) ) {
        wp_remove_object_terms( $object_id, $default, 'category' );
    }
}, 10, 4 );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Drop "Uncategorized" When Another Category Is Chosen" 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/
