Tuesday, January 6, 2015

Hide categories from your WordPress homepage

Using the WordPress's Loop , pre_get_posts, you can hide certain categories from your homepage. In your theme's functions.php, add these following:

function hide_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-5, -34' );
}
return $query;
}

add_filter( 'pre_get_posts', 'hide_category_home' );

5 and 34 are IDs of categories you want to hide.

Cool!