Skip to content

Instantly share code, notes, and snippets.

@braddalton
Last active August 15, 2017 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braddalton/5021613 to your computer and use it in GitHub Desktop.
Save braddalton/5021613 to your computer and use it in GitHub Desktop.
Exclude posts from one or more categories from displaying on your home page http://wpsites.net/web-design/exclude-category-posts-page/
add_action( 'pre_get_posts', 'exclude_category_posts' );
/**
* @author Brad Dalton - WP Sites
* @example http://wpsites.net/web-design/exclude-category-posts-page/
*/
function exclude_category_posts( $query ) {
if( $query->is_main_query() && $query->is_home() ) {
$query->set( 'cat', array( -27, -30 ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment