Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Farmatique/9d5d6288c114e081f23a940e4dd6fdbc to your computer and use it in GitHub Desktop.
Save Farmatique/9d5d6288c114e081f23a940e4dd6fdbc to your computer and use it in GitHub Desktop.
Wordpress. Exclude post category from homepage or blog
//Remember the ID number of the category (in this case, the number is 55)
//Open functions.php file from the active theme
//Copy and paste the code and replace “xx” with the category ID (leave the minus sign in the code)
function exclude_category($query) {
if ( $query->is_home() ) {// set this to "is_archive()" to remove from blog
$query->set( 'cat', '-xx' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_category' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment