How-to: Exclude a Post Category from the Blog Page only

By default, you can exclude Posts Categories from appearing in your Blog, RSS or Site Map pages. This is specially useful when creating a Slider Category or even a Gallery category that is not meant to be seen anywhere else. This is done in Site Options > Blog Settings. However, there may be times where you wish to exclude a certain Category from the just Blog page. Here are your instructions: Access the functions.php file (Appearance > Editor) and add the following code:

function exclude_category($query) {  if ( $query->is_home() )  {  $query->set('cat', '-XX');  }  return $query;  }   add_filter('pre_get_posts', 'exclude_category');

Make sure you keep the minus sign (-), only replace XX, nothing more! If you wish to exclude more than one Category, you just need the Category ID of each category you wish to exclude. Post that Category ID along with the minus sign right before it in the same space as other category IDs, but separate them with spaces. So the final code would look something like this:

function exclude_category($query) {  if ( $query->is_home() )  {  $query->set('cat', '-XX -YY -XY -XYZ');  }  return $query;  }   add_filter('pre_get_posts', 'exclude_category');

How to find the Category ID #? You can see it by taking a look at the URL of the page in your browser’s address bar. It is the number towards the end of the URL, right after the equal sign. The URL should end with something like this &tag_ID=XX&post_type=post where XX is a number. (note, it could be a single, double or triple digit number, depending on how many categories your WordPress blog has. Some blogs could get four or five digit number. Just mark down the number in full as it appears after the equal sign).