Removing Categories from your RSS feed

Removing Categories from your RSS feed:
It’s pretty straightforward. Just go into your feed files and add a filter saying: “if the post is in one of these categories, don’t include it in the feed”. Well, that’s the basic concept. Here are the details:I edited the /wp-includes/feed-rss.php & /wp-includes/feed-rss2.php You probably should also do the atomfeeds and others found inside wp-includes, but everyone who is subscribed to our blog uses Google Reader, and afaik, Google uses RSS, so I didn’t bother. I added the following lines just after the beginning of the loop and right after the

while have_posts : the_post:

Add this php code:

if ((!(in_category(53))) && (!(in_category(55))) &&
(!(in_category(56)))) : {

Where 53, 55 & 56 are categories that you don’t want in your feed. Notice that this is an if statement and this ends with an opening curly brace. So all you have to do is close this if statement.

You must close the if statement at the bottom of the file by issuing a closing curly brace and an endif statement just before the endwhile. So the bottom of my “feed-rss.php” looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php while (have_posts()) : the_post(); ?>
<?php if ((!(in_category(53))) && (!(in_category(55))) && (!(in_category(56)))) : { ?>
<item>
<title><?php the_title_rss() ?></title>
<?php if (get_option('rss_use_excerpt')) { ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php } else { // use content ?>
<description><?php the_content_rss(, 0,, get_option(’rss_excerpt_length’)) ?></description>
<?php } ?>
<link><?php permalink_single_rss() ?></link>
<?php do_action(’rss_item’); ?>
</item>
<?php } endif; ?>
<?php endwhile; ?>
</channel>
</rss>

The Codex article can be found here: Customizing Feeds.

Comments

Got something to say?