Excluding Categories on the Front Page

This example shows how to remove posts from the specified categories from the output on the blog’s front page. For example, we have 2 categories with IDs 1 and 1347 that we do not need to show on the front page. To exclude these categories from the query, use this code in a plugin or in a theme:

add_action( 'pre_get_posts', 'exclude_category_on_front_page' );

function exclude_category_on_front_page( $query ) {

	if ( $query->is_front_page() && $query->is_main_query() ) {

		$query->set( 'cat', '-1,-1347' );
	}
}

Note embeded into: pre_get_posts