How to Hide a Specific Post in WordPress

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

While it is possible to make WordPress posts password protected or private, in some cases you might simply would like to specific hide the post from your homepage while still allowing others to view it if they have the direct link.

In this blog post, we are going to show you how to hide a specific post from selected pages in WordPress. It could be your homepage, category archives, search results, and other pages.

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 have to do is install and activate the WordPress Hide Posts plugin. For more details, see our step by step guide about how to install a WordPress plugin.

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

Simply clicking on it will reveal plugin options. You will be able to hide the post on the front page and blog page, category or tag pages, authors page, and website search results.

Simply select the options you like and after that save your post.

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

Only users who have the direct post URL (permalink) will be able to still see it by entering the URL.

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

For example, you will not be able to hide a page or even 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 website. In case you have not done this before then see our guide about how to copy and paste code snippets in WordPress.

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

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

You will be able to add custom code using the code snippets plugin which is safer and does not break your WordPress website. Alternatively, you will be able to add the custom code to your theme’s functions.php file.

You will also have to know the IDs of the post or pages which you would like to hide. We have got a quick tutorial about how to find a post ID in WordPress that shows how to find a post ID.

Basically, you will be able to 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 us dive into the code part.

Hide WordPress Posts or Pages from Homepage

The following code uses is_home() conditional tag to find out when 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');

Do not forget to replace the IDs inside the array with the actual IDs of posts or pages which you would like to exclude.

Hide WordPress Posts or Pages from RSS Feed

In case you would like to hide a WordPress post from the homepage as well as the WordPress RSS feed, then you have to 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 Website Search

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

You can now visit your WordPress website and look 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 have 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|how you can|the best way to|the way to} hide a WordPress post or page from specific areas. Now, what about completely hiding a WordPress post from {all these|all of these} areas at once?

To do that, you will have to 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.

We hope this blog post helped you learn How to Hide a specific Post in WordPress homepage and other pages of your WordPress website. You might also want to see our guide about how to make a WordPress website completely private.

In case you liked this blog post, then please sign up to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

1 thought on “How to Hide a Specific Post in WordPress”

  1. Hi Louise,

    After laboring to create an informative article, one may not see the need to hide a post. However, many factors can contribute to that – leading marketers to protect their blog posts. The tips you presented are worth applying. Thanks for sharing!

    Reply

Leave a Comment