Exclude Posts from Main Archive

This snippet excludes specific posts from the main archive page, useful for hiding certain content from general archives.

PHP

function exclude_posts_from_archive($query) {
    if ($query->is_archive() && $query->is_main_query()) {
        $query->set('post__not_in', array(1, 2, 3)); // Replace with post IDs to exclude
    }
}
add_action('pre_get_posts', 'exclude_posts_from_archive');

Snippet Feedback

Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.

Tags

Language

Did it work?

Save Snippet

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.