Exclude Categories from RSS Feed with functions.php

Snippets by IsItWP

Are you looking for a way to delete categories from RSS feed using your theme’s functions.php file? While there’s probably a plugin for this, we have created a quick code snippet that you can use to exclude categories from RSS feed with functions.php in WordPress.


All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin. Then, add the IDs of the categories you wish to exclude on line 3 (currently set to 20, 21, and 22). Make sure to use a minus, “-“, before the category ID.

function exclude_cat_wps($query) {
    if ($query->is_feed) {
    return $query;

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: How to create a WordPress membership site and 9 best WordPress ad management plugins to boost revenue.

Comments  Leave a Reply

  1. thank

  2. Does this take some time to update? I followed these instructions exactly but the category’s posts are still showing up in the RSS2.0 feed.

    1. Hi Zachary
      No this should work right away, do you have any other code that may cause this to have problems? RSS related plugins,

Add a Comment Cancel reply

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!