Skip to content

Instantly share code, notes, and snippets.

@jpmarchand
Last active January 29, 2017 02:34
Show Gist options
  • Save jpmarchand/512e5a9ec0fb9ce2e12f to your computer and use it in GitHub Desktop.
Save jpmarchand/512e5a9ec0fb9ce2e12f to your computer and use it in GitHub Desktop.
Exclude posts of specific categories from blog homepage. Source: http://www.wpmayor.com/how-to-hide-or-remove-categories-from-a-wordpress-homepage/
<?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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment