How to Hide a Post From the WordPress Homepage

Hide a Post From the WordPress HomepageWant to hide a blog post from your WordPress homepage or blog archive page? You can password secure or make WordPress posts private, in certain materials you may also want to hide the post from your homepage while allowing others to see it if you have an immediate link. In this article, we are going to let you the know-how

to hide posts from WordPress pages like the landing page.

Method 1. Hide a WordPress post from the main page using a plugin

This method is more straightforward and it is prescribed for beginners to use it.

The primary thing you really want to do is to install and activate the Hide Posts WordPress plugin.

After the plugin is activated, edit the post you want to hide. In the right segment of the editor, you will see a new “Hide Posts” section

At the point when you click on it, you can see its options. You can hide the post on the front page, blog page, category or tag pages, author page, and site search results.

Just select the options you like and then save your post.

Depending on the options you have picked, you can now visit those pages and that particular post won’t be shown.

All users who have a standard mail address (permalink) can in any case see it by entering the URL.

While this is a basic method, it lacks several options.

For example, you cannot hide a page or a custom post type like WooCommerce items. It also doesn’t have an option to hide a post from the WordPress RSS channel.

Method 2. Manually hide WordPress posts and pages

In this method, you want to add a code to your WordPress site.

You can add custom code using the code bits plugin, which is safer and won’t break your site. Alternatively, you can add custom code to your theme’s functions.php file or a site-specific plugin.

You also need the ID of the post or pages you want to hide. To do this, go to the post-editing section so you can see its ID in the address bar of your program

Hide WordPress posts or pages from the landing page.

In the code beneath, the conditional tag is_home () is used to determine whether the user is viewing the landing page or not.

To do this, you should use the following code.

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');

Don’t neglect to replace the IDs in the array with the actual IDs of the posts or pages you want to eliminate.

More from us: WordPress Update; A Step-By-Step Guide

Hide WordPress posts or pages from the RSS channel

If you want to hide a WordPress post from the homepage as well as the WordPress RSS channel, you can just use the 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');

Now if you’re signed in as an admin and attempt to visit your WordPress RSS channel, you’ll in any case see the posts recorded there. Other users cannot see erased posts while viewing your RSS channel.

Hide WordPress post or page from site search

Now, what would it be advisable for you to do if you want to hide certain posts from WordPress site search? To do this, you essentially have to 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 see your website and search for the posts you wanted to hide. Although these posts are public, they don’t appear in search results.

Hide WordPress post or page from the archive.

How about hiding specific WordPress posts or pages from archive pages like categories, tags, and archive history? For this, we use the conditional tag (is_archive).

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');

How to Hide WordPress Post or Page From Everywhere

Up to this part of the article, we have learned how to hide a WordPress post or page from certain areas. Now, how about completely hiding a WordPress post from all these sections at once?

To do this, you can combine all the conditional tags we used earlier into a single code scrap.

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');

This code hides posts from the homepage, RSS channel, search results, and archive pages.

 

You may also like...

Leave a Reply

Your email address will not be published.