Blog

You've reached the blog of Jeremie Tisseau, a French Visual Interface Designer, Wordpress & Drupal developer, graphic designer, web addicted... Oh! and I am based in Bangkok, Thailand, with my family.

Next/Previous Post

Join Us!

Open source Wordpress theme by the WPSynergy communityAre you a talented WP designer or developer?

More Info

Hire Me!

I am currently available for Web/UI design projects. If you think we would work well together, contact me today to receive a free consultation.

Get in touch!

October 20, 2008

All, PHP, Tutorials, Wordpress

4 Ways to Exclude WordPress Category from RSS Feeds

Article written by Jeeremie

Lately, 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:

1
<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:

1
<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:

1
<a href="<?php bloginfo('url'); ?>/feed=rss2&cat=-3,-12">Entries (RSS)</a>

If you are using RSS2, your code will be:

1
<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:

1
<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:

1
2
3
4
5
6
7
8
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:

?View Code HTML4STRICT
1
2
<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>

The Author

Article written by Jeeremie:

Hi, My Name is Jeremie Tisseau. I am a Visual Interface Designer focusing on Web Applications design, Wordpress/drupal development... I am also the founder of WPSynergy, an open source community focusing on building high quality Wordpress themes... for Free!

Want to become a guest author on this blog?

9 Comments

  1. Jeffro2pt0 says:

    24 Oct, 2008

    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.

  2. Peter S says:

    9 Jan, 2009

    Thanks so much. It is just what I’m looking for :)

  3. Darren Sproat says:

    24 Mar, 2009

    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

  4. Waterman pens says:

    1 Apr, 2009

    Woww, Thank you brother . Very good theme .

  5. Prearlinuri says:

    17 Apr, 2009

    nice, really nice!

  6. Steve G. says:

    25 Jan, 2010

    Thanks for sharing. That’s the tutorial I’m looking for!

  7. thank you for this exclude categories, but i want to exclude the main default one…. thank you :)

  8. Bad Bone says:

    26 Feb, 2010

    Nice article..I tell my friend to read this and bookmark..

  9. Allen says:

    13 Jul, 2010

    Thank you. I’ve been trying to hide my slider and photo gallery category rss feeds by using plugins, but they caused more confusion. Finally I found your article and after a while, got it to work perfectly.
    Appreciate your help…. too bad I’m gonna get all the credit for this. :)
    Thanks Jeremie.

Leave a Reply