How to Exclude Posts of Certain Tags from WordPress Blog Homepage
Home » » How to Exclude Posts of Certain Tags from WordPress Blog Homepage

How to Exclude Posts of Certain Tags from WordPress Blog Homepage

Sometimes you may want to exclude posts of certain tag from your WordPress blog’s homepage. Suppose you write paid reviews about some services or freewares available on internet and you don’t like those reviews to appear on your blog’s homepage. You can add a tag to review posts and then exclude the posts of that tag from homepage of your blog. This article will explain you two ways to hide posts of a certain tag from main page of WordPress blog.
First method is for advanced users and the other method is for beginners. If you are an advanced WordPress user then you can easily edit your theme files.

Method 1

This method is for advanced users and not recommended for beginners.
  • Go to Appearance -> Editor in your WordPress dashboard and then select Main Index Template.
  • Now copy the following code:
    <?php
    if (is_home()) {
    global $wp_query;
    $wp_query->set("tag__not_in", array(12));
    $wp_query->get_posts();
    }
    ?>
    and paste it above:
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
  • Now save the file and see the result.

Method 2

This method uses a plugin. So beginners can use this method easily.
Here is a WordPress plugin “Simply Exclude” which can be used to exclude posts based on certain tags and even categories from your blog’s homepage. Once installed you can go to the Settings of Simply Exclude plugin and select Exclude tags in your WordPress dashboard. There you can select multiple tags to stop their posts from appearing on homepage, archive, search or even feed.
I don’t recommend the use of plugins for simple modifications. If you are comfortable with editing theme files, you must chose the first method. However its always better to take backup of your complete theme before making any modifications.
Share this article :

1 comment: