RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

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.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment