How to exclude a category from your WordPress homepage

To exclude a category simple include this code snippet in your WordPress theme’s functions.php file. It is best practice to add this to your child theme as the change will be lost when you update your theme.

function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-8' );
return $query;
add_filter( 'pre_get_posts', 'exclude_category_home' );

The number next to ‘cat’ would be the ID of the category that you are looking to exclude.