Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggregation Enquires Welcome

Example Interest Rates: Home Loan Variable: 2.54% (2.74%*) • Home Loan Fixed: 3.74% (3.8%*) • Fixed: 2.48% (2.94%*) • Variable: 2.54% (2.74%*) • Investment IO: 2.3% (3.76%*) • Investment PI: 2.04% (3.8%*)

Exclude Posts from WordPress Blog or RSS Feed Based on Tag

Further to our snippet on removing a category from an RSS feed, this snippet will exclude posts with a specific tag from either showing up in your blog or RSS feed.

The first snippet will prevent a post from showing up on your WordPress website.

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
<?php 
2
/*
3
 Exclude Posts from WordPress Blog or RSS Feed Based on Tag
4
 http://www.beliefmedia.com/code/wp-snippets/exclude-posts-wordpress-tag
5
*/
6
 
7
function exclude_post_tag($query) {
8
  if ( $query->is_home) {
9
   $query-> set('tag__not_in',array(3));
10
  }
11
 return $query;
12
}
13
add_filter('pre_get_posts','exclude_post_tag');

If you wanted to exclude multiple tags from showing up, you would do so as follows: $query-> set('tag__not_in',array(3, 4, 5, 6)); and so on. Keep in mind that the numbers relate to the tag ID that you can identify by hovering your mouse over the tag in your WordPress control panel.

Using a variation of the code above, you can easily exclude posts from showing in your WordPress RSS feed. An RSS feed is often considered to be 'selective content', and many bloggers wish to control what information is made available outside of their website. You can accomplish this using the following code.

1
<?php 
2
/*
3
 Exclude Posts from WordPress Blog or RSS Feed Based on Tag
4
 http://www.beliefmedia.com/code/wp-snippets/exclude-posts-wordpress-tag
5
*/
6
 
7
function exclude_tag_rss($query) {
8
  if ( $query->is_feed) {
9
   $query-> set('tag__not_in',array(34));
10
  }
11
 return $query;
12
}
13
add_filter('pre_get_posts','exclude_tag_rss');

You can remove multiple tags from your RSS feed using the method described above.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  AUS Eastern Standard Time (Washington)

  Want to have a chat?
 

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment