window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/svg\/","svgExt":".svg","source":{"concatemoji":"https:\/\/wpbrilliance.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=5.2.4"}}; !function(a,b,c){function d(a,b){var c=String.fromCharCode;l.clearRect(0,0,k.width,k.height),l.fillText(c.apply(this,a),0,0);var d=k.toDataURL();l.clearRect(0,0,k.width,k.height),l.fillText(c.apply(this,b),0,0);var e=k.toDataURL();return d===e}function e(a){var b;if(!l||!l.fillText)return!1;switch(l.textBaseline="top",l.font="600 32px Arial",a){case"flag":return!(b=d([55356,56826,55356,56819],[55356,56826,8203,55356,56819]))&&(b=d([55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447],[55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447]),!b);case"emoji":return b=d([55357,56424,55356,57342,8205,55358,56605,8205,55357,56424,55356,57340],[55357,56424,55356,57342,8203,55358,56605,8203,55357,56424,55356,57340]),!b}return!1}function f(a){var c=b.createElement("script");c.src=a,c.defer=c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var g,h,i,j,k=b.createElement("canvas"),l=k.getContext&&k.getContext("2d");for(j=Array("flag","emoji"),c.supports={everything:!0,everythingExceptFlag:!0},i=0;i
Oct 1, 2019
3 Views
0

How to Hide a Post From Home Page in WordPress

Written by

Have you ever wanted to hide a blog post from your WordPress homepage or blog archive page? While you can make WordPress posts password protected or private, in some cases you may simply want to hide the post from your homepage while still allowing others to view it if they have the direct link. In this article, we will show you how to hide posts from selected pages in WordPress such as homepage, category archives, search results, and more. Method 1. Hide a WordPress Post from Homepage Using a Plugin This method is easier, and it is recommended for beginners. First thing you…

Have you ever wanted to hide a blog post from your WordPress homepage or blog archive page?

While you can make WordPress posts password protected or private, in some cases you may simply want to hide the post from your homepage while still allowing others to view it if they have the direct link.

In this article, we will show you how to hide posts from selected pages in WordPress such as homepage, category archives, search results, and more.

Hide Posts from Home Page in WordPress

Method 1. Hide a WordPress Post from Homepage Using a Plugin

This method is easier, and it is recommended for beginners.

First thing you need to do is install and activate the WordPress Hide Posts plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Once the plugin is activated, go ahead and edit the post you want to hide. You will notice a new ‘Hide Posts’ section in the right column of the editor.

Hide posts settings

Clicking on it will reveal plugin options. You can hide the post on the front page and blog page, category or tag pages, authors page, and site search results.

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

Depending on the options you selected, you can now visit those pages and that particular post will not be listed.

All users who have the direct post URL (permalink) can still see it by entering the URL.

While this method is the easiest, it lacks several powerful options.

For example, you cannot hide a page or a custom post type like a WooCommerce products. It also does not have an option to hide a post from WordPress RSS feed.

Method 2. Manually Hide WordPress Posts and Pages

This method requires you to add code to your WordPress site. If you have not done this before then see our guide on how to copy and paste code snippets in WordPress.

WordPress uses a database query to fetch and display posts based on the page a user is viewing. It also provides built-in hooks to modify the query before running it.

We will be using those hooks to modify the WordPress query and hide the WordPress posts, pages, and custom post types in different sections.

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

You will also need the IDs of the post or pages that you want to hide. We have a quick tutorial on how to find a post ID in WordPress that shows how to get this information.

Basically, you can just edit a post or page to view its ID in your browser’s address bar.

Finding a post ID in the address bar

That being said, let’s dive into the code part.

Hide WordPress Posts or Pages from Homepage

The following code uses is_home() conditional tag to find out if the user is viewing the homepage. If they are, then it excludes 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');

Don’t forget to replace the IDs inside the array with the actual IDs of posts or pages that you want to exclude.

Hide WordPress Posts or Pages from RSS Feed

If you want to hide a WordPress post from the homepage as well as the WordPress RSS feed, then you can simply 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 are logged in as an administrator and tried to visit your WordPress RSS feed, then you will still see the posts listed there. Other users will not be able to see the excluded posts when they view your RSS feed.

Hide WordPress Post or Page from Site Search

Now, what if you wanted to hide specific posts from WordPress site search? To do that, you’ll simply need 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');

You can now visit your website and search for the posts you wanted to hide. Even though these posts are public, they will not appear in search results.

Post excluded from search results

Hide WordPress Post or Page from Archives

How about hiding specific WordPress posts or pages from archive pages like category, tags, and date archives? To do that, we will 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

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

To do that, you can combine all the conditional tags we have used earlier 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');

This code will hide the given posts from homepage, RSS feed, search results, and archive pages.

Controlling Content Visibility in WordPress

You can hide WordPress posts or pages using the two methods we described above. Let’s answer some of the most frequently asked questions about content visibility control options in WordPress.

Do these methods perfectly hide content?

No, they don’t.

For example, search engines may have already crawled and indexed the post before you can hide it. If you want to prevent search engines, then see our guide on how to hide a WordPress page from Google.

This also will not work if a WordPress plugin uses a custom query that skips your checks and reveals the content you are trying to hide.

A better approach would be to password protect a post so that only users with the password can view it.

You can also create a private post which is only visible to the administrators, editors and authors on your website.

Can I use these methods to create content for specific users?

No, these methods do not allow you to efficiently share content with specific users. A better approach would be to use a WordPress membership plugin.

Membership plugins like MemberPress allow you to create and publish restricted content. You can even sell subscription plans to access premium content.

For more details, see our guide on how to create a WordPress membership website with step by step instructions.

We hope this article helped you learn how to hide a WordPress post from the homepage and other areas of your website. You may also want to see our guide on how to make a WordPress site completely private.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Hide a Post From Home Page in WordPress appeared first on WPBeginner.

Article Categories:
WordPress Plugins

Leave a Reply

Your email address will not be published. Required fields are marked *

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc a odio nec justo rutrum faucibus.
$20
Buy Now