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 jminfotech.com
* @link http://www.jminfotech.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 code, 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
Labels:
Wordpress
Previous Article

Responses
0 Respones to "How to exclude a category from the loop on your home page"
Post a Comment