How to exclude a category from your blog's feed

lyttieOften you'll want to exclude a particular category from your blog's RSS feed - whether it's an archive of your Twitter posts, or a category you're using for some kind of housekeeping. It's easy to do - just edit the category number in this code, and add it to your theme's functions.php file.

function feed_the_cat($query) {
if ($query->is_feed) {
$query->set('cat','-1');
//change the category ID to the relevant one;
//don't forget the minus sign!
}
return $query;
}
add_filter('pre_get_posts','feed_the_cat');

If you don't have a functions.php file in your theme, then create a new file in Notepad, type <?php + the above code + ?> - then save and upload to your theme's folder.

Memo to self: stop getting silly with function names.

Share this post:
  • email
  • del.icio.us
  • Facebook
  • FriendFeed
  • LinkedIn
  • StumbleUpon
  • Tumblr
  • Twitter

Tags: , , ,

Posted by Sue on July 27, 2009 in WordPress.

One comment to "How to exclude a category from your blog's feed"

  1. CTL wrote:

    It is so useful! Thanks.

Leave a Reply