# Return 404 for Empty Category and Tag Pages

> Shows your "not found" page with a 404 status for categories, tags and other terms that have no published posts, instead of an empty archive.

- Type: PHP
- Runs: Run everywhere
- Category: [Archives](https://wpide.com/library/category/archive/)
- Tags: archives, 404, thin-content
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/empty-term-archives-404/

## Code

```php
add_action( 'template_redirect', function () {
    global $wp_query;

    if ( ( is_category() || is_tag() || is_tax() ) && ! is_paged() && ! $wp_query->have_posts() ) {
        $wp_query->set_404();
        status_header( 404 );
        nocache_headers();
    }
}, 1 );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Return 404 for Empty Category and Tag Pages" 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/
