How to: exclude categories from your rss feed

October 24, 2008 at 9:47 am

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!