In this article, I’ll demonstrate advanced techniques to hide posts or pages in WordPress from the main blogroll, home page, archive pages, search results, and RSS feeds without a dedicated third-party plugin.
Why Hide Posts or Pages in WordPress?
There are numerous reasons why you would want to hide posts or pages from specific areas of your WordPress site. For instance, I have individual pages that should never show up in the search results of the internal search function of WordPress. Examples of such pages include the “Thank You” or “Confirmation” pages of newsletter subscription and other forms.
Additionally, I don’t want sponsored posts to clutter up my blogroll or RSS feed, and thus, I’d like to hide them in those areas.
Available Methods to Hide Posts or Pages
While searching for a solution that could help me achieve my goals, I stumbled across a few different methods to hide posts in WordPress.
Unfortunately, none of the popular solutions worked for me. For the sake of completeness, I’ll briefly mention them in this article anyway, before showing you what has worked best for me.
Post Visibility
When you publish a post or page in WordPress, its visibility, by default is set to Public. But you can change the visibility setting to Private, which renders the post or page inaccessible to everyone but logged in users. While this is a useful setting for specific occasions, it does not solve the problem of hiding individual blog posts or pages in only some areas of your WordPress site.
WP Hide Post WordPress Plugin
The third-party plugin WP Hide Post sounded very promising at first because its author claims to offer the specific features I was looking for. Upon closer inspection, I noticed a couple of issues and I decided not to use the plugin, including:
- The plugin hasn’t been updated in over a year
- It costs $3 per month to access all of its features
- It got some terrible reviews lately
- Some users have complained about performance issues
WordPress Hooks
As a result, I needed a better solution and came up with a couple of simple hooks that would hide individual posts and pages from the following areas in WordPress:
- Search results
- Blogroll / Homepage
- Archive pages (Tag, Category, Year, Month, Day)
- RSS feed
To accomplish that, I needed a way to add WordPress hooks without having to modify my theme or any other standard code. There are various plugins available that allow you to add code to WordPress, but I’m using one called Code Snippets. So before you do anything else, go ahead and download and activate that plugin. While you are at it, also download a plugin named Show IDs by 99 Robots. I’ll explain later what we’ll need that for.
WordPress Query Filter And Pre Get Posts
The specific hooks we need to hide posts or pages are a combination of the so-called “query” filter and “pre get posts” action. If you have never used the WordPress API and its hooks and all of this sounds scary, don’t worry. I’ll explain first the theory and then walk you through the implementation step-by-step.
What we’ll do is, create a couple of custom functions – one for each area we would like to hide posts and pages from and then feed them to the WordPress API.
Hide Posts/ Pages From Search
The function to hide posts or pages from the WordPress internal search results looks like this:
function exclude_posts_pages_from_search( $query ) {
if ( ! $query->is_admin && $query->is_search && $query->is_main_query() ) {
/*
61986 - Thank you Page
69489 - Post about why the sky is blue
*/
$query->set( 'post__not_in', array(61986, 69489 ) );
}
The code above takes the standard WordPress query object as an input argument and then manipulates it to exclude specific post or page IDs from the final search results. If you are not sure how you can find those IDs, don’t worry, I’ll show you later.
Note that I’ve added a comment (the text between / / to the function above to document what post or page each ID corresponds to. That makes it easier to find and remove them later.
To further customize how the function works, I’m using the following flags:
- ! is_admin: only triggers the code that follows for regular users (i.e., Visitors) but not for logged in administrators
- is_search: targets the search results only
- is_main_query(): Makes sure we are dealing with the primary WordPress query
The last statement in my custom function manipulates the query by leveraging the “post__not_in” statement, followed by an array of post or page IDs that I’d like to exclude.
To inject our custom function into WordPress, we can use the add_action call that looks like this:
add_action( 'pre_get_posts', 'exclude_posts_pages_from_search' );
Hide Posts/Pages From Blog Roll
The function to hide posts or pages from the main blogroll is similar to the one we used for the search.
function exclude_single_posts_home($query) {
if ($query->is_home() && $query->is_main_query()) {
$query->set('post__not_in', array(69489, 69177,68878,68736));
}
}
In the function above, we use is_home() instead of is_search() to check if the query is executing on the home page or main blogroll.
The matching action hook is:
add_action('pre_get_posts', 'exclude_single_posts_home');
Hide Posts/Pages From Archive Pages
Archive pages are special pages in WordPress and include the following:
- Category pages
- Tag pages
- Date archives (Year, Month, Day)
To hide individual post/page IDs from such pages, you can use the following function and action hook:
function exclude_single_posts_archive($query) {
if ($query->is_archive() && $query->is_main_query()) {
$query->set('post__not_in', array(69489, 69177,68878,68736));
}
}
add_action('pre_get_posts', 'exclude_single_posts_archive');
As I’m sure you have noticed, we have replaced is_home() with is_archive(). Pretty straightforward, huh?
Hide Posts/Pages From RSS Feeds
Last but not least, the following function hides posts and pages from your RSS feed.
function exclude_single_posts_feed($query) {
if ($query->is_feed() && $query->is_main_query()) {
$query->set('post__not_in', array(69489, 69177,68878,68736));
}
}
add_action('pre_get_posts', 'exclude_single_posts_feed');
The conditional function to pay attention to is is_feed().
Combining Functions
While you certainly can use four separate functions to hide posts or pages from all the areas we discussed above, you can also combine them into a single function, which would look like this:
function exclude_single_posts($query) {
if (($query->is_home() || $query->is_archive() || $query->is_feed() || $query->is_search()) && $query->is_main_query()) {
$query->set('post__not_in', array(69489, 69177,68878,68736));
}
}
add_action('pre_get_posts', 'exclude_single_posts');
Note how I used parentheses () and the || (or) && (and) operator to hide an array of post/page IDs from the home page/blogroll, archive pages, RSS feeds and search results.
How to Hide Posts or Pages in WordPress
Now that you understand the theoretical aspect of hiding posts or pages in WordPress let get to the practical portion of this exercise!
Before we get started, double check that you have installed and activated the two plugins I mentioned at the beginning of the article.
Write down the Post/Page IDs you want to hide
Then go to your Posts inside of WordPress Admin and take note of the post IDs you’d like to hide. If you don’t see the ID column, click on the Screen Options drop-down at the top of your screen and make sure “ID” is selected. If you don’t see an option for “ID,” chances are, you haven’t installed or activated the Show IDs plugin.
Create a Code Snippet
Next, navigate to the Snippets dashboard and click on “Add New.” Then paste one of the snippets from above, for instance, the combined snippet and replace the IDs with your own.
Once done, click on the “Save Changes and Activate” button and confirm that you don’t see any syntax errors. If you would like to deactivate or disable a snippet, simply toggle the switch in front of the snippet’s name.
Last but not least, open a new browser window and test the results. If you have used the is_admin() function, you may have to open the browser window in incognito mode for your code snippet to kick in.
Frequently Asked Questions
How Do I Know If My Code Snippets Work?
To verify that your code snippets work, check your blog roll, and the relevant archive pages (tags, categories) associated with the posts or pages you hid. That’s relatively straightforward.
To find out if you have successfully excluded individual pages from search is also easy, even if you don’t have a search box on your webpage. You can easily simulate a search by using the ?s=search+term suffix. For example, if I want to search this blog for “How to hide posts,” I can hit the following URL in my browser:
https://michaelkummer.com/?s=how+to+hide+posts
If I don’t see any relevant results, I know it worked. Depending on if you intended to hide certain posts or pages only from users who are not logged in to the WP backend, you have to test using a separate browser window running in incognito (or private browsing) mode.
In other words, make sure that you’re not accidentally logged into WordPress. Otherwise, you might still see the hidden posts.
Does Hiding Posts or Pages Impact SEO?
It depends! If you have submitted a sitemap to your target search engines (i.e., Google), and if the hidden posts or pages are still in your sitemap, indexable and not set to NoIndex, hiding them from search or other areas of your page will likely not impact SEO.
However, if SEO is your goal, then why hide them on your page? That doesn’t make sense unless you have a particular use case that I don’t know about.
I Want to Create a Private Page For Clients, How Can I Accomplish That?
If you want to create a private page for individual clients that should not be visible to anyone else, including search engines, then the above methods are probably not the best method of accomplishing that.
Of course, you could use the above snippets to hide that page and then remove the page from your sitemap, and set it to NoIndex, using a plugin, such as Yoast.
Alternatively, you could set the page Visibility to Private or Password Protected and either create user accounts for your clients or give them the password.
For more advanced scenarios, you could try a membership plugin.
Conclusion
The WordPress API and its hooks are incredibly powerful tools in your tool belt. And now that you know how to Hide Posts and Pages in WordPress, I’m sure you’ll find other use cases for them to customize your site. If you have any questions or concerns, leave a comment below, and I’ll do my best to answer them.

I’m a healthy living and technology enthusiast.
On this blog, I share in-depth product reviews, actionable information and solutions to complex problems in plain and easy-to-understand language.
Hi Michael
Thanks for the post.
How will this code change if I want:
-> Users to register
-> Select categories they prefer / or exclude those they don’t (Similar to Spotify sign up process)
-> Save to user profile
-> Home page for them is now personalised to their categories they have chosen
-> and every time they log in it remembers their custom home page
Much like the plugin, but personalised for each user (when logged in), so different home page for every user based on their selection.
Hi Max,
What you’re trying to accomplish goes way beyond a simple snippet. You’d have to create a plugin for that or find an existing membership plugin that can do that.
Cheers,
Michael
Hey
Not sure if you can help me. I’ve been looking everywhere for days for information about having more control over my posts/categories. I want to hide certain posts from certain posts, even if they share categories (not sure if that makes sense).
All the information I can find online is to hide a post from search, RSS or the blog page. And all the code seems to be site/theme-wide and not for individual posts. I’m sure there’s an easy way to do this, but I just can’t find anyone writing about it anywhere.
Any clues? Do I even make sense?
I’m not sure I understand your use case 100%. Can you send a marked-up screenshot of what you want to achieve?
Hello thank you for the great tips.
I am interested in hiding a page that is not to be available when you land on the page. Yet, would like tbe page to be indexed and crawled and being searchable by the search engines and SEO.
How do I go about that? Make the page private, yet somehow add the page in the sitemap.xml file or add the address as an independent sitemap.xml?
Thanks
What you could do is check for the user agent to determine if a search engine bot or a regular browser is viewing the page. Based on that, you can show the regular content, or something else.
Show Only this codes