Below is the code to exclude posts of specific categories from the blog homepage.
This file contains 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 | |
//* Exclude categories from blog homepage | |
function customprefix_exclude_categories_home($query) { | |
if ($query->is_main_query() && $query->is_home()) { | |
$query->set('cat', '-5,-34'); // Precede category IDs with a minus sign | |
} | |
} | |
add_action('pre_get_posts', 'customprefix_exclude_categories_home'); |