How to Exclude a Category from Your WordPress Feed

How to Exclude a Category from Your WordPress Feed

If you’ve ever wanted to keep a certain category out of your RSS feed, there’s an easy way to do that. Just place the following code in your Functions file. (Appearance > Editor > Theme Functions – functions.php)

Simply insert the ID number from the category that you want to exclude in the spot where you see the “1” in the example below. (Note: include the minus sign — e.g. -2, -5, etc.)

If you aren’t sure how to find the ID for your categories, you can take a look at this post.


function excludecatfeed($query) {
               if(is_feed()) {
                              return $query;
add_filter('pre_get_posts', 'excludecatfeed');


If you would like to exclude more than one category, then just include the other ID numbers beside the first like so:

$query->set('cat','-1, -5, -7');

The Code in Action

And here’s the function in action. You can see that the three posts from the my “Video” category have all disappeared after I excluded that category.



Photo: Rss icon from BigStock