WordPress exclude specific category from blog page

Code Examples, PHP, Wordpress

WordPress exclude specific category from blog page

function exclude_category( $query ) {
	if ( $query->is_home() && $query->is_main_query() ) {
	    $query->set( 'cat', '-126' );
	}
}
add_action( 'pre_get_posts', 'exclude_category' );

Here, 126 is category id and minus sign tells to exclude.

click for more WordPress codes, read in detail about WordPress Categories and WordPress Query.