Close Panel
 
 

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:

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

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

Technorati Tags: , ,

Popularity: 10% [?]

 

Related posts

| Subscribe to Feed | Email the author

18 Responses to “4 Ways to Exclude WordPress Category from RSS Feeds”

  1. 1
    WordPress News &amp; Notes - October 23, 2008 | Wordpress Blog Services Says:

    [...] 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. [...]

  2. 2
    Jeffro2pt0 Says:

    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.

  3. 3
    WordPress News & Notes - October 23, 2008 | Radyoplay IP-TV Technologie Says:

    [...] 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. [...]

  4. 4
    Peter S Says:

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

  5. 5
    Darren Sproat Says:

    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

  6. 6
    Kategorie im Feed ausschließen Says:

    [...] 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. [...]

  7. 7
    Waterman pens Says:

    Woww, Thank you brother . Very good theme .

  8. 8
    Prearlinuri Says:

    nice, really nice!

  9. 9
    Come (ma Soprattutto Perché) Implementare un Sideblog - seconda parte » Francesco Gavello - Blog Marketing Tips, Web & Blogosfera Says:

    [...] 4 Ways to Exclude WordPress Category from RSS Feeds (grazie PiccoloSocrate!) [...]

  10. 10
    Items of interest » Blog Archive » Bookmarks for July 14th through July 15th Says:

    [...] Web-kreation – 4 Ways to Exclude WordPress Category from RSS Feeds – [...]

  11. 11
    links for 2009-07-29 — girliegeek Says:

    [...] Web-kreation – 4 Ways to Exclude WordPress Category from RSS Feeds (tags: wordpress exclude category feed post RSS content) [...]

  12. 12
    10 Códigos útiles para WordPress | Blog and Web Says:

    [...] Web Kreation / Vía Ayuda [...]

  13. 13
    10 Códigos útiles para WordPress - Crear Tu WebSite Says:

    [...] Web Kreation / Vía Ayuda [...]

  14. 14
    10 Códigos útiles para WordPress | Alojate.com Tu Proveedor de Web Hosting, Dominios, VPS, Servidores Dedicados, Factura Electrónica y Marketing para Buscadores en México Says:

    [...] Web Kreation / Vía Ayuda [...]

  15. 15
    Exclude Categories from Feed, Archives, Search, and Home page in WordPress | WP Garage Says:

    [...] Place the following code in your functions.php file replacing 12 with your category and commas for additional categories. Tip from Web Kreation. [...]

  16. 16
    Steve G. Says:

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

  17. 17
    Bouncy Castle Hire Weston-Super-Mare Says:

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

  18. 18
    Bad Bone Says:

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

 

Leave a Reply

Wrap all code in <pre lang="LANGUAGE" colla="-">...</pre> and replace 'LANGUAGE' by 'html4strict' for HTML, 'php', 'javascript', 'css'...