Keep Tagged Posts Out of RSS Feeds
Leaves any post with a "no-feed" tag out of all RSS feeds, so you can publish a post on the site without sending it to subscribers and newsletter tools.
Opens WPIDE on
Code
// Tag slug that keeps a post out of feeds.
$wpide_no_feed_tag = 'no-feed';
add_action( 'pre_get_posts', function ( $query ) use ( $wpide_no_feed_tag ) {
if ( is_admin() || ! $query->is_main_query() || ! $query->is_feed() || $query->is_comment_feed() ) {
return;
}
$tag = get_term_by( 'slug', $wpide_no_feed_tag, 'post_tag' );
if ( $tag ) {
$query->set( 'tag__not_in', array_merge( (array) $query->get( 'tag__not_in' ), array( (int) $tag->term_id ) ) );
}
} );
Notes
Create a tag with the slug no-feed (or change the slug at the top) and add it to posts you want to hide from feeds.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.