How to exclude a category from the loop on your home page

Just add this WordPress Code Snippet to the functions.php file in your current WordPress theme in order to exclude one or more categories from the loop on your home page.

/**
 * Exclude certain categories from home page loop
 *
 * @author WPSnacks.com
 * @link http://www.wpsnacks.com
 */
function exclude_categories($query) {
  if ( $query->is_home ) {
    $query->set('cat', '-1,-5,-10');
  }
  return $query;
}
add_filter('pre_get_posts', 'exclude_categories');

In the above function, the -1, -5, and -10 can be replaced by the Category ID for whichever category or categories you want to exclude from your home page loop. This function above would exclude categories 1, 5, and 10 from the home page.

Hope this helps. Enjoy.

   Related Sponsored Links

Disclaimer: The information contained in this website is for general information purposes only and in no event will this site or its owners be liable for any losses or damages associated with your use of our site or content. Click here to see our full Disclaimer.

Leave a Comment

*