Exclude Posts from the RSS Feed by Tag or Category

Sometimes you may want to publish a post, but not have it distributed to your RSS feed or mailing list. For whatever reason you may have to want to do this, there is a simple solution to achieve this.

One of the things to pay close attention to below, is that all of these use the ID and not the name of the tag or category.

Add the code you need to your functions.php file in your theme folder. You can easily modify any of the snippets of code to fit your needs as well.

Exclude a Single Tag from RSS

function exclude_tag_rss($query) {
if ( $query->is_feed) {
	$query-> set('tag__not_in',array(34));
	}
return $query;
}
add_filter('pre_get_posts','exclude_tag_rss');

Exclude Multiple Tags from RSS

function exclude_tags_rss($query) {
if ( $query->is_feed) {
	$query-> set('tag__not_in',array(34,73));
	}
return $query;
}
add_filter('pre_get_posts','exclude_tags_rss');

Exclude a Single Category from RSS

function exclude_cat_rss($query) {
if ( $query->is_feed) {
	$query-> set('category__not_in',array(3));
	}
return $query;
}
add_filter('pre_get_posts','exclude_cat_rss');

Exclude Multiple Categories from RSS

function exclude_cats_rss($query) {
if ( $query->is_feed) {
	$query-> set('category__not_in',array(2,15));
	}
return $query;
}
add_filter('pre_get_posts','exclude_cats_rss');

If you have any suggestions or other examples you’d like to share, please leave them in the comments.

Comments

  1. By vb078 on

    How to know if it’s working in Feedburner (linked to my original WP feed) ?
    Any time to regenerate ? (to be like my original WP feed)

    Thx for all your tips :)
    seeya

    Reply »

  2. By vb078 on

    Find a ATOMIC way in feedburner :)
    > Trooblshootize tab >>> resync now button
    Seeya

    Reply »

  3. By on

    Thanks for sharing this code. It was exactly what we needed for setting up our RSS driven email campaigns.

    I appreciate your generosity.

    Thanks,
    Vi

    Reply »

Leave a Reply

Your email address will not be published. Required fields are marked *