How to: exclude categories from your rss feed

Depending to your blog structure, it may be interesting to exclude some categories from your rss feeds. If you always wanted to find a clean way to do it, I’m pretty sure this recipe will make you happy.

Before starting to code, you'll have to know the numeric ID of the categories you want to exclude. If you don't know how to get the ID of a particular category, just read this recipe.

Once you have the ID of the categories you want to exclude from your rss feed, open the functions.php file from your theme. If your theme doesn't have a functions.php file, create one.

Paste the following code in it:

function myFilter($query) {
    if ($query->is_feed) {
        $query->set('cat','-5'); //Don't forget to change the category ID =^o^=
    }
return $query;
}

add_filter('pre_get_posts','myFilter');

Credit goes to Scott Jangro for this awesome recipe!

3 Responses

Oct 02 2011 22:18

Great, that worked fine – thanks a lot!

Do you happen to know how to hide/remove the WP native gallery images from the feed so that only the featured image is displayed..?

Cheers
Thomas

Apr 20 2012 11:33

Hi there

Thanks for this. I want to exclude four categories from my general feed, but I do want to be able to allow the feed from those categories (they are one category plus three sub-categories) to appear in the category feed.

If I follow your code, would this prevent the category feed from producing any entries?

May 08 2012 17:51

thanks
but i want to remove categories Feed from browser menu
how can i do that please
thanks

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox