# Skip Category and Tag Pages With Only One Post

> Sends visitors straight to the post when a category or tag archive contains just one post, saving them a pointless extra click.

- Type: PHP
- Runs: Run everywhere
- Category: [Archives](https://wpide.com/library/category/archive/)
- Tags: archives, redirect, categories
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/redirect-single-post-archives/

## Code

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

    if ( ! ( is_category() || is_tag() ) || is_paged() || is_feed() ) {
        return;
    }

    if ( 1 === (int) $wp_query->found_posts && ! empty( $wp_query->posts[0] ) ) {
        wp_safe_redirect( get_permalink( $wp_query->posts[0] ), 302 );
        exit;
    }
} );
```

## Notes

Uses a temporary redirect, so the archive works normally again as soon as a second post is added.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Skip Category and Tag Pages With Only One Post" 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/
