How to Exclude Categories from RSS Feed in WordPress


wplogo-stacked-rgbLast week I wrote about how to disable WordPress RSS feed completely from end users. Sometimes there are cases where we want posts from certain categories not to publish in RSS feed; we just wish to unpublish post in feed.

There are 2 ways to disable categories in feeds.

1. If you’re a feedburner user

You’ll have to edit the original feed source in your feedburner account like below;

http://designgala.com/feed?cat=-7&cat=-18

Above URL would exclude posts from categories with ID 7 and 18

2. From standard RSS feed

In order to use this method, you need to add following code in function.php of your active theme.

/**
* disable RSS feed
*/
function exclude_categories_in_feed($query) {
	if ($query->is_feed) {
        $query->set('cat','-7,-18');
return $query;
}
 
add_filter('pre_get_posts','exclude_categories_in_feed');

I hope this was short but cool wordpress hack to exclude categories from RSS feed.

2 total comments on this postSubmit yours
  1. Hi,
    I tried to use the code for the standard RSS feed and got an error. I think you are missing a closing bracket. Where should it go?
    Thank you!

  2. Doesn’t work for me.

5 total pingbacks on this post
Submit your comment

Please enter your name

Your name is required

Please enter a valid email address

An email address is required

Please enter your message

Design Gala © 2012 All Rights Reserved

Developed by 76 Miles

Powered by WordPress