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.

7 Comments How to Exclude Categories from RSS Feed in WordPress

  1. Pingback: WordPress Rocker

  2. Pingback: Design Gala

  3. Pingback: Anish Lama

  4. Pingback: WordPress Rocker

  5. Pingback: WordPress Rocker

  6. beachy

    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!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>