There can be several reasons for excluding a category or multiple categories from WordPress RSS feed and I am sure you have one. It really easy to exclude a list of categories from WordPress RSS feed. Just paste this code in your theme’s functions.php file,
function catFilter($query) {
if ($query->is_feed) {
$query->set('cat','-12');
}
return $query;
}
add_filter('pre_get_posts','catFilter');
if ($query->is_feed) {
$query->set('cat','-12');
}
return $query;
}
add_filter('pre_get_posts','catFilter');
This code will remove all posts assigned to the category ID 12 from the RSS feed of your WordPress site. If you want to exclude multiple categories, then put a list of categories separated by commas in the code above, like this:
function catFilter($query) {
if ($query->is_feed) {
$query->set('cat','-12,-14,-10');
}
return $query;
}
add_filter('pre_get_posts','catFilter');
if ($query->is_feed) {
$query->set('cat','-12,-14,-10');
}
return $query;
}
add_filter('pre_get_posts','catFilter');
If you are not sure about how to find the ID of any category, then go to Posts > Categories in your WordPress dashboard, and hover over any category. You’ll see the ID of the category in the status bar of your browser.