20
Oct
2008
4 Ways to Exclude WordPress Category from RSS Feeds
By jeeremie. Posted in PHP, WordpressLately, I wanted to exclude a few categories from Wordpress Feeds. A search on Wordpress didn’t return any valuable information. So, I searched the Google database. Here’s what I found:
1- Change the feed URL
The most common and maybe easier way to do so is to change your feed structure. In the default Wordpress theme, the RSS link (in footer.php) is:
<a href="<?php bloginfo('rss2_url'); ?>">Entries (RSS)</a> |
You can exclude any category by appending a query string to the feed URL, like this:
<a href="<?php bloginfo('url'); ?>/feed?cat=-3&cat=-12">Entries (RSS)</a> |
‘12‘ in this example is your category ID. In older version of Wordpress, the category IDs were displayed in Manage -> Categories, next to category name. However, in Wordpress 2.5+, the Wordpress Gurus removed this feature (only god knows why). To identify the category ID, mouseover the category name to see its ID in the status bar of your browser. Otherwise, you can install Reveal IDs for WP Admin 2.5 plugin to reveal the post, page and category IDs.
A more common PHP structure might work as well:
<a href="<?php bloginfo('url'); ?>/feed=rss2&cat=-3,-12">Entries (RSS)</a> |
If you are using RSS2, your code will be:
<a href="<?php bloginfo('url'); ?>/feed=rss2&cat=-3&cat=-12">Entries (RSS 2)</a> |
Depending on your permalink structure, you might need to add index.php to your feed url:
<a href="<?php bloginfo('url'); ?>/index.php?feed=rss2&cat=-5">Entries (RSS 2)</a> |
2- Exclude categories in your template’s functions.php file
Jangro explains how to exclude a category from feed by adding a few lines of code to the template’s functions.php file:
function myFeedExcluder($query) { if ($query->is_feed) { $query->set('cat','-12'); } return $query; } add_filter('pre_get_posts','myFeedExcluder'); |
This code will keep the category ID=”12″ out of the feed. If you want to exclude more than one category, put them in separated by commas ‘-12,-25,-33′.
3- Add a plugin to Wordpress
If you are not into coding, you can install the Ultimate Category Excluder plugin. It allows to exclude any categories from your front page, archives, and feeds. Once you installed it, go to the Category Exclusion page in your admin panel to exclude a category by selecting one. That is that easy.
You can also install the Stealth Publish plugin to exclude a specific post from being published in feeds.
4- Exclude category from RSS feeds in FeedBurner
If like me you are using FeedBurner, go to dashboard and click “Edit Feed Details”. In the field “Original Feed”, enter the feed URL with the categories you want to exclude as explained in first step above.

Conclusion
The methods described above would be interesting to implement if you write about two (or more) different topics on your site. Let’s say you write about Linux (which would be ID=”1″ in our example below) and Windows (ID=”2″). Some of your readers might want to read your Linux articles but not the Windows ones, and vice-versa. Thus, you could create two feed links, the first one excluding Windows feeds for your Linux reader and the second one the Linux feeds:
<a href="http://yourdomain.com/feed?cat=-2">Subscribe to Linux Feed</a> <a href="http://yourdomain.com/feed?cat=-1">Subscribe to Windows Feed</a> |
Popularity: 10% [?]


October 23rd, 2008 at 3:26 pm
[...] How to Exclude Categories from your RSS Feed – Have a few categories on your blog that you don’t want your feed readers to see? Web Kreation has written a great post explaining how to prevent certain categories from showing up in your feed. [...]
October 24th, 2008 at 7:55 am
Question regarding this action. Would any of these 4 methods allow me to import a WXR file that contained a few categories from showing up in the feed reader? I don’t want my current subscriber base of 500 to be bombarded with new posts when I import a WXR file into my existing installation.
October 25th, 2008 at 9:06 am
[...] How to Exclude Categories from your RSS Feed – Have a few categories on your blog that you don’t want your feed readers to see? Web Kreation has written a great post explaining how to prevent certain categories from showing up in your feed. [...]
January 9th, 2009 at 7:57 pm
Thanks so much. It is just what I’m looking for
March 24th, 2009 at 1:06 pm
THANK YOU!
I have been looking for category exclusion code for controlling what is displayed on the default/home/front pages for what seems like ages! Like you, a search on wordpress didn’t turn up the results I was looking for… a move to google found your site and the info should allow me to do what I need to do…
Thanks again,
Darren Sproat
March 27th, 2009 at 1:01 am
[...] Code ist nicht von mir, ich fand ihn vor langer Zeit bei Web Kreation und bei diesem Kommentar . Ich habe ehrlich keine Ahnung woher er als 1. [...]
April 1st, 2009 at 3:04 pm
Woww, Thank you brother . Very good theme .
April 17th, 2009 at 6:35 am
nice, really nice!
July 13th, 2009 at 10:35 am
[...] 4 Ways to Exclude WordPress Category from RSS Feeds (grazie PiccoloSocrate!) [...]
July 15th, 2009 at 5:14 pm
[...] Web-kreation – 4 Ways to Exclude WordPress Category from RSS Feeds – [...]
July 29th, 2009 at 2:03 pm
[...] Web-kreation – 4 Ways to Exclude WordPress Category from RSS Feeds (tags: wordpress exclude category feed post RSS content) [...]
August 27th, 2009 at 10:13 am
[...] Web Kreation / Vía Ayuda [...]
September 14th, 2009 at 12:00 am
[...] Web Kreation / Vía Ayuda [...]
October 3rd, 2009 at 5:41 am
[...] Web Kreation / Vía Ayuda [...]
January 14th, 2010 at 1:12 pm
[...] Place the following code in your functions.php file replacing 12 with your category and commas for additional categories. Tip from Web Kreation. [...]
January 25th, 2010 at 4:35 am
Thanks for sharing. That’s the tutorial I’m looking for!
February 14th, 2010 at 4:46 am
thank you for this exclude categories, but i want to exclude the main default one…. thank you
February 26th, 2010 at 2:31 pm
Nice article..I tell my friend to read this and bookmark..