This snippet lets WordPress users exclude a category or categories from their blog page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //* mind this opening php tag | |
//* Exclude categories from blog page | |
add_filter('pre_get_posts', 'rv_exclude_blog_categories'); | |
function rv_exclude_blog_categories($query) { | |
if ($query->is_home) { | |
$query->set('cat', '-1,-2,-3'); //Replace with your category numbers (keep negative signs) | |
} | |
return $query; | |
} |
Leave a Reply