Dukeo » WordPress » Exclude Categories from RSS Feed: How To This on WordPress

Exclude Categories from RSS Feed: How To This on WordPress

Steven WordPress

You may have certain categories on your WordPress blog that you want to display on your site, but that you want to exclude from your RSS feed.

First thing to do is getting the ID of the category you want to exclude from your WordPress feed. To do that, go to the Categories admin page and put your mouse over the category you want to exclude. If you take a look at the status bar of your web-browser, you’ll see the category ID.

Once you retrieved the category ID, you need to paste the following code in the functions.php file of your WordPress theme:

function dukeoRSSFilter($query) {
  if ($query->is_feed) {
    $query->set('cat','-5'); // Replace 5 by Category ID
  }
return $query;
}
add_filter('pre_get_posts','dukeoRSSFilter');

If you enjoyed this article,
Get email updates

Join for Free »