Exclude Certain Category Posts From the Blog Page

The correct way to exclude categories from main blog page, is to make use of pre_get_posts which change the query variable before the main query is executed. The following is an example;

function exclude_category($query) {
    if ($query->is_home() && $query->is_main_query()) {
        $query->set('cat', '-3,-6');
    }
}
add_action('pre_get_posts', 'exclude_category');

For the full list of available parameters you can use with pre_get_posts, please visit WP_Query codex page.

Categories: Tutorials

 

 

Please Leave a Reply

If you don't have anything nice to say, pretty please don't go on and ruin my day. I'd appreciate your kindness very much. Thank you :)