WordPress.org

Support

Support » How-To and Troubleshooting » How to Configure? Posts with tag "x" to not appear on main blog page

How to Configure? Posts with tag "x" to not appear on main blog page

Viewing 3 replies - 1 through 3 (of 3 total)
  • On the main blog page, find this:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    blah blah blah
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    and replace it with this:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <?php
    $blockit = "no";
    $posttags = get_the_tags();
    if ($posttags) {
      foreach($posttags as $tag) {
        if($tag->name=="x") {
    $blockit = "yes";
    }
    }
    }
    ?>
    
    <?php if($blockit=="no") { ?>
    
    blah blah blah
    
    <?php }; ?>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    Wow! And if I wanted an easier answer with no coding?!? ;/

    function voodoo_exclude_tag( $query ) {
         if( $query->is_main_query() && $query->is_home() ) {
              $query->set( 'tag_id', '-4' );
         }
    }
    
    add_action( 'pre_get_posts', 'voodoo_exclude_tag' );

    There might be a plugin to modify what’s displayed on the homepage. Not sure…

    Here’s another code example… that might be a bit easier to implement. You would need to adjust the -4 to your tag ID, which can be found on the admin side by looking at the url presented for that particular tag (in the tags admin menu, usually found by hovering on the tag title). Fo rinstance:

    http://domain.com/wp-admin/edit-tags.php?action=edit&taxonomy=post_tag&tag_ID=39&post_type=post

    The tag ID here is 39

    So, to exclude it in the above query we use -39

    This little bit of code can just go into functions.php in the theme

    You could also keep looking for a plugin, of course! I just don’t know of any offhand…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to Configure? Posts with tag "x" to not appear on main blog page’ is closed to new replies.