How to Hide a Post From Home Page in WordPress?

How to Hide a Post From Home Page in WordPress?:- Are you want to hide a post from WordPress home page or blog archive page? If yes then this post is helpful for you in hide posts from your website. In this post we will tell you some methods to hide your post.

Hide a Post From Home Page in WordPress

Method 1. By using a plugin Hide a WordPress Post from Homepage

If you are a WordPress beginner then this method is very easy and helpful to you.

First thing you need to install WordPress. After setup you need to install WordPress Hide Post plugin. Once your plugin is activated then edit your post which you want to do hide. Here you will see a “hide posts” section in the right column of editor. Click on it. This will reveal plugin options. You have to option of hide your WordPress post from blog page, category or tag pages, authors pages and also site search result.

Now choose the option you like and then save your post. You can visit on the selected page and see that particular post will not be listed. If you have post URL then you can direct see it by entering URL.

This method is very easy and have several powerful options too.

Method 2. Manually Hide WordPress Posts and Pages

If you want to hide your WordPress post manually then you have t be need of coding. Because this methods requires add code in you WordPress website.

WordPress use a database query to fetch and display posts on your website. The posts are based on the page user is viewing. WordPress provides built in hooks to modify the query before running it. We will use this hooks to modify query and hide the WordPress post from the home page, custom post and any other different section. You can add the code ysing the code snippets plugin which is the safe and not break you website.

Besides you can also add the code in functions.php file and site specific plugin.Now you will need to ID of the post and pages that you want to hide from your WordPress.

Hide WordPress Posts or Pages from Homepage

You can use the following codeon your homepage that is _home() and also use conditional tag to find out if the user is viewing the homepage. If they are then it is not included the post IDs from the query.

function wpb_exclude_from_home($query) {

      if ($query->is_home() ) {

          $query->set(‘post__not_in’, array(1737, 1718));

      }

}

add_action(‘pre_get_posts’, ‘wpb_exclude_from_home’);

please don’t forget to replace the IDs inside array with the actual IDs of your pages and posts  that you want to remove.

Hide WordPress Posts or Pages from RSS Feed

If you want to hide the WordPress post from the homepage as well as the WordPress RSS feed then you should be needed a code to insert in WordPress. You can use code is_feed conditional tag in the code.

function wpb_exclude_from_feed($query) {

      if ($query->is_feed() ) {

          $query->set(‘post__not_in’, array(1737, 1718));

      }

}

add_action(‘pre_get_posts’, ‘wpb_exclude_from_feed’);

If you are a administrator and logged into your WordPress to visit your RSS Feed then you will still see your posts listed there. Other users can’t view your posts in your RSS feed.

Hide WordPress Post or Page from Site Search

If you want to hide specific posts from WordPress site search then you will simpally add the is_search conditional tag to the code.

function wpb_exclude_from_search($query) {

      if ( $query->is_search() ) {

          $query->set(‘post__not_in’, array(1737, 1718));

      }

}

add_action(‘pre_get_posts’, ‘wpb_exclude_from_search’);

Now you can visit to your website and search for the posts which you want to hide. These post are public and they will not appear in search result.

Hide WordPress Post or Page from Archives

If you want to hide specific WordPress posts or pages from archive pages like category,tags and date archives then we have to use the is_archive() conditional tag.

function wpb_exclude_from_archives($query) {

      if ( $query->is_archive() ) {

          $query->set(‘post__not_in’, array(1737, 1718));

      }

}

add_action(‘pre_get_posts’, ‘wpb_exclude_from_archives’);

Hiding WordPress Post or Page from Everywhere

Now we learned how to hide a post from specific areas. So, what about completely hiding a WordPress post form all these areas at once?

For hide posts from all area you have to be need the conditional tags which we have used in a single code snippet.

function wpb_exclude_from_everywhere($query) {

      if ( $query->is_home() || $query->is_feed() ||  $query->is_search() || $query->is_archive() ) {

          $query->set(‘post__not_in’, array(1737, 1718));

      }

}

add_action(‘pre_get_posts’, ‘wpb_exclude_from_everywhere’);

By using this code you will hide the given post from homepage, RSS feed, Search result, and archive pages.