How To Exclude A Category From Your WordPress Feed
Today I’d like to share with all of you this nice WordPress trick I stumbled on created by Joseph Foley; it shows you how to exclude one or more category from your WP feed. All it takes is for you to insert the following code in your functions.php file.
function excludecatfeed($query) {
if(is_feed()) {
$query->set('cat','-1');
return $query;
}
} add_filter('pre_get_posts', 'excludecatfeed');
Just indicate the ID number of the category you want excluded. In the above code, the ID number is “1”. Just replace the value if needed and just leave the minus “-“ symbol as is. To exclude more categories, just append the ID number separated by a comma (see example below).
$query->set('cat','-1, -5, -7');
Hope some of you find this nice little trick useful. Have a good day, everyone!
$query->set(‘cat’,'-1, -5, -7′); |