WordPress Made Easy

How to Hide a Post From Home Page in WordPress

Ever wished to keep a blog article hidden from your WordPress home page or blog archives?

While WordPress posts can be made private or password protected, there are times when you may only want to conceal a certain post from your site while still allowing visitors who have the direct link to access it.

This article will demonstrate how to conceal posts from specific WordPress pages, including the home page, category archives, search results, and more.

WordPress: Hide Posts from Home Page

Method 1: Using a plugin, conceal a WordPress post from the homepage

Beginners are advised to use this strategy because it is simpler.

Installing and activating the WordPress Hide Posts plugin should come first. See our step-by-step tutorial on installing a WordPress plugin for more information.

Edit the post you want to hide after the plugin has been enabled. You’ll see a new “Hide Posts” area in the editor’s right column.

hide settings for posts

Options for plugins can be seen by clicking on it. On the home page, blog page, category or tag pages, authors page, and site search results, you can choose to conceal the post.

Simply make your selections, then save your post.

You can now access those pages, but that particular post won’t be listed depending on the parameters you chose.

By entering the URL, any user who has the direct post URL (permalink) can still access it.

Although this approach is the simplest, it lacks a number of potent alternatives.

You cannot, for instance, make a custom post type like a WooCommerce product or a page invisible. Additionally, there is no mechanism to remove an article from the WordPress RSS feed.

Method 2: Hiding WordPress Pages and Posts by Hand

You must add code to your WordPress website in order to use this strategy. See our tutorial on how to copy and paste code snippets in WordPress if you’ve never done it before.

Depending on the page a user is browsing, WordPress will retrieve and display posts from a database query. Additionally, it offers built-in hooks to change the query before executing it.

These hooks will be used to alter the WordPress query and conceal the posts, pages, and custom post types in certain areas.

The code snippets plugin allows you to add custom code in a safer and non-breaking manner. As an alternative, you can include the custom code in a site-specific plugin or the functions.php file of your theme.

The IDs of the posts or pages that you want to conceal are also required.

In essence, you may just change a post or page to see its ID in the URL bar of your browser.

A post ID can be found in the address bar.

So let’s get started with the code section.

WordPress Posts or Pages Can Be Hiding From Homepage

The is home() conditional tag is used in the following code to determine whether the user is viewing the homepage. If so, the post IDs are disregarded from the search.

1
2
3
4
5
6
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 forget to substitute the actual IDs of the posts or pages you wish to exclude for those contained in the array’s IDs.

WordPress Posts or Pages Can Be Hiding From RSS Feed

Use the is feed conditional tag in the code to easily hide a WordPress article from both the homepage and the WordPress RSS feed.

1
2
3
4
5
6
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 attempt to access your WordPress RSS feed while logged in as an administrator, you will still see the entries posted there. When other people access your RSS feed, they won’t be able to see the excluded posts.

WordPress Post or Page Search Hide

What if you wanted to keep some posts from appearing in the WordPress site search? Simply add the is search conditional tag to the code to accomplish that.

1
2
3
4
5
6
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 that the posts you wished to hide are available, you can search your website for them. These posts are open to the public, but they won’t show up in search results.

Post not returned in search results

Archive-specific WordPress post or page hiding

How about preventing certain WordPress pages or posts from appearing on archive sites like date, category, and tag archives? We’ll employ the is archive() conditional tag to accomplish that.

1
2
3
4
5
6
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 a WordPress page or post from the public

We have so far learned how to restrict access to a WordPress page or post. What if you could instantly hide a WordPress article from every one of these locations?

You can accomplish that by combining all the conditional tags we previously used into a single piece of code.

1
2
3
4
5
6
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');

The specified posts will be hidden from the homepage, RSS feed, search results, and archive pages by using this code.

WordPress Controlling Content Visibility

These two techniques can be used to hide WordPress pages or posts. Let’s address some of the most often asked queries regarding WordPress’s content visibility management features.

Do these techniques entirely conceal the content?

Not at all, no.

Before you can conceal a post, for instance, search engines might have already browsed and indexed it.

Additionally, if a WordPress plugin employs a custom query that omits your tests and displays the content you are attempting to conceal, this will not function.

Password-protecting a post so that only users with the password can view it would be a better strategy.

Additionally, you have the option of creating a private post that is only accessible to the website’s administrators, editors, and authors.

Can I produce material for particular users using these techniques?

No, you cannot effectively share content with particular people using these approaches. Using a WordPress membership plugin might be a better strategy.

You can build and publish limited content with membership plugins like MemberPress. Even subscriptions to access premium material are marketable.

We sincerely hope that this article has taught you how to remove a WordPress post from your website’s front page and other locations.

Comments are closed.