HowTo – Excluding A Category From Your WordPress RSS Feeds

Filed under: Wordpress Tips

Providing content to our viewers in the way they want to consume it is the best way to attract visitors.

There are a variety of ways to intercept the visitors browser type and send them content that is formatted specifically for their device. We have just started working with some settings that allow our mobile phone web visitors easier access by trimming down our themes and displaying readable text and modified images.

Some of your visitors may be using your RSS feeds for inclusion in their online aps or they may be reusing your content for publication on their site. Many times this is to your advantage but some times you would rather not have your content snarfed up by RSS Readers and used to build someone else’s content.

You probably already know that you can trim your posts to show your excerpts. You can also include notices in your feeds as to your content being copyrighted.

Even so you may just want to completely exclude a single or many categories from your feeds.
This is a good idea if you have directory information that you update often.. The content in those categories would be interesting to your visitors but you don’t want to flood your RSS visitors with ten posts of names and addresses.

Whatever your reason you can add a function to your functions.php file in your theme directory to exclude specific categories from your feed.

 

[php]

function exclude_cat_from_feed($query) {
if ($query->is_feed) {
$query->set(‘cat’,’-1,-9,-73′);  // to exclude cats 1, 9 and 73
}
return $query;
}
add_filter(‘pre_get_posts’,’exclude_cat_from_feed’);

[/php]

 

To find the IDs of your categories install the Reveal IDs Plugin from the WordPress Repository then browse your category listings. The ids are displayed on the right side of the page.