I'd like to exclude Tag ID: 26 from my homepage. I've figured out how to do it with categories, but not with tags.

function exclude_posts( $query ) { 
if ( $query->is_home ) {  $query->set( 'cat', '-13' ); 
} } add_action( 'pre_get_posts', 'exclude_posts' );

This should work

function exclude_posts( $query ) { 

    if ( $query->is_home() ) {  

        $query->set( 'tag__not_in', array( 13 ) ); 



add_action( 'pre_get_posts', 'exclude_posts' );

tag and tag_id are not set up like cat to accept negative numbers (ID numbers) for exclusion (conclusion based on experiments, not digging into the code (some other time, perhaps!)). Also, all of the examples in the Codex use is_home(), is_admin(), etc., but apparently is_home does work - without the ().

| improve this answer | |
  • Hi CK, your code worked. Thanks for sharing it as well as the explanation! – Kareem Sayeed Oct 31 '17 at 16:25
  • You're welcome, but please don't forget to mark my answer as good/accepted - as I close in on the magic 1000 mark! – CK MacLeod Oct 31 '17 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.