hide specific posts

How to hide specific posts on Wordpress

Do You want to hide some of your posts from the front page or Blog Page?

I Understand, Sometimes you want to create a “low-profile” addition to your blog.

In other words, want to hide specific posts that don’t belong on the front page, or maybe you don’t want it to show up anywhere else in your blog except when you explicitly link to it.

If you would like to hide a particular blog post on your website homepage or blog page. It is quite easy and there are two ways to do it. We will discuss both of them.

1 Hide Posts from the Specific Category Completely

This approach hides all the posts in a certain category of your choice.

Instead of hiding every single post, You can hide the whole category from showing up on the homepage or blog page.

You need to add the below code snippet in your theme’s functions.php file. replacing the category IDs with the ones you want to exclude:

function exclude_category($query) {
if ( $query->is_home() ) {
$query->set( 'cat', '-3' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_category' );

This prevents posts from category with ID number 3 to be shown upon the homepage and blog page.

Notice the number ‘3’ in 3rd line? You need to replace that with your own category ID.

2 Hide posts from archive pages

In case, you would like to hide posts to appear on archive pages such as category, tags, author pages.

You will need to use the following snippet instead.

function exclude_single_posts_archive($query) {
	 if ($query->is_archive() && $query->is_main_query()) {
		  $query->set('post__not_in', array(1223, 776,878));
	  }
}
add_action('pre_get_posts', 'exclude_single_posts_archive');

The numbers you notice in the above code is Post ID’s. if you are not sure how to find a post or category ID, I have a video for you for the instructions.

Watch the video below If you don’t know how to check Category Id

3 Use Of Plugin To Hide Specific Posts

WP Hide Post – This plugin excels in giving you full control over the visibility of your a post.

It’s been more than 2 years when the plugin was last updated at the time of writing of this post.
So please make sure you don’t have any errors on your website after having activated this.

By default, any post you add to your WordPress blog will become the topmost post and will show up immediately on the front page in the first position, and similarly in the category, tags and archive pages.

This plugin allows you to create such “hidden gems”.

In particular, this plugin allows you to control the visibility of a post in various different views:

  • The Front Page (Homepage, depending on your theme, this may not be relevant)
  • The Category Page (listing the posts belonging to a category)
  • The Tag Page (listing the posts tagged with a given tag)
  • The Authors Page (listing the posts belonging to an author)
  • The Archive Pages (listing the posts belonging to time period: month, week, day, etc..)
  • The Search Results
  • Feeds

The posts will disappear from the places you choose them to disappear.

Everywhere else they will show up as regular posts.

In particular, permalinks of the posts still work, and the fun part is it will not affect SEO ranking for that particular post as the post will be on Your Sitemap as well.

This means that the content of your post will be indexed and searchable by search engines.

If you want to hide the WordPress page, this plugin also allows you to control the visibility with two options:

  • Hide a page on the front page (homepage) only.
  • Hide a page everywhere in the blog (hiding the page in the search results is optional).

Technically, whenever pages are listed somewhere using the get_pagesfilter, this plugin will kick in and either filter it out or not according to the options you choose.

The same rules apply regarding permalinks and sitemaps as they do for regular posts.

“WP Hide Post” plugin is a great tool in your arsenal for SEO optimization.

It allows you to add plenty of content to your blog, without forcing you to change the nature and presentation of your front page,

for example.

You can now create content that you otherwise would be reluctant to add to your blog because it would show immediately on the front page, or somewhere else where it would not belong.

I hope this article has helped you to hide specific posts on your site. Let me know in the comments below if need any assistant.

3 Comments

Leave a Reply

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