So, How to hide a page in WordPress is a big question nowadays.
There might be several reasons that you want to hide a page in WordPress from some of your users (Membership site) or you want to hide it from Google.
In today’s tutorial, we’ll cover each and every aspect and show you How to hide a page in WordPress without affecting the SEO of your site.
Why would you want to hide a page?
As a website owner, you may want to exclude some content from search engines like Google.
Hiding information from Google is particularly useful if your website is still in progress and you want to give your visitors a sneak peek. This prevents Google from indexing an incomplete webpage in its search results.
If you have a membership website, you can also benefit from eliminating WordPress pages from search results. You can prevent search engines from indexing your members’ profile pages.
MemberPress is one of the best plugins for creating a membership website. Do check it out.
Furthermore, eliminating pages containing private or sensitive information protects your privacy and prevents personal information from falling into the wrong hands.
In this tutorial, we’ll go through how to hide WordPress pages from Google using HTML meta tags, robots.txt files, and password protection.
Method 1: Hide Posts Using WordPress Visibility Settings
This method uses a unique strategy. Instead of asking search engines not to index a page, you can password protect it so that only those who know the password can see it.
You can set the visibility option for a post and a page as you want. By default, it will be set as ‘Public’
But if you want to change it, to private or password protected then you can do it by going to the right side of your screen and you will see the Status & Visibility section, from there you can change its settings.
It comes with the following features:
Public: This option allows anybody to see your post or page. Everyone can see what you’ve written.
Private: This setting allows you to restrict the display of your post or page to site administrators and editors. This implies that users who do not have admin or editing access will be unable to see your post. You may control who can see your post or page by assigning these responsibilities.
Password-protected: You can make your post or page password-protected. All users who do not have the password will be unable to see the post. When you want others to see your content, you can share your password.
If you want to password protect a page, just click on the ‘Public’ in front of visibility and then select password protected.
Now enter your password and now, you can publish or save your post.
Now visitors accessing the post or page on your website will be asked to enter the password to view the content.
If you’re looking to create and sell online courses, then we recommend using a proper platform like MemberPress which comes with advanced content protection features.
Method 2: Hide a page in WordPress using Rankmath
If you are a beginner and don’t want to hustle with code then you can follow this method.
First, you need to install a plugin named Rankmath. Once the plugin is installed and activated, go to the page or the post that you wish to hide and under its title, you will see the ‘Quick Edit’ option, click on it.
After this, you will see this type of interface, Here you need to click on the no-index and then update the post.
No-indexing means that the page or post won’t be included in your site’s sitemap, alternatively, it is hidden from browsers.
If you wish to hide posts or pages in bulk then simply select all the posts and from the drop-down select Set to no-index.
Now you know How to hide a page in WordPress. The above two mentioned methods are the easiest ones if you are a beginner, and you should follow those methods in order to learn How to hide a page in WordPress.
But if you are an expert and want to hide pages in bulk then you can continue with the third method to hide a page in WordPress.
Method 3: Use Category to Hide Posts or Pages in Bulk
For pages that you want to hide, you can create a category. You can, for example, create a category called “Hidden” for posts that you want to keep hidden from the general public.
Simply add the content you want to hide to this category.
We’ll now look at how to hide all posts that are in a particular category.
Before we go any further, you’ll need a Category ID and a Post ID. How will you get it? You can use the Show IDs By 99robots.
It’s a straightforward plugin that shows post, page, and category IDs. Because we’ll be using these IDs a lot in this WordPress tutorial, make sure you’ve installed this plugin.
Check out our guide on Installing WordPress Plugins, for more details.
Make sure you’ve installed this plugin on your WordPress site because we’ll be using these IDs a lot in this WordPress tutorial. Once the plugin is activated, You will see the IDs of the posts and pages.
Once you have the category ID, insert the following code snippet in your theme’s functions.php file.
function exclude_category($query) {
if ( $query->is_home() ) {
$query->set( 'cat', '- Category ID' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_category' );
Make sure to add the category ID (that you want to hide) into this code. Suppose that your category ID is 481 then you will write ‘-481’ instead of ‘-Category ID’.
And the code will look like this
function exclude_category($query) {
if ( $query->is_home() ) {
$query->set( 'cat', '-481' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_category' );
This code will hide all the posts of pages that are inside this category.
Method 4: How to hide a page in WordPress using robots.txt
This solution needs the updating of the robots.txt file. Incorrect instructions in this file can have a negative impact on your site’s SEO, which is why it is not suggested for newbies.
The robots.txt file is a configuration file that you can place in the root directory of your WordPress site. The name robots.txt comes from the fact that it allows a website to provide instructions for search engine bots.
You can edit robots.txt files by connecting to your website using an FTP client or ‘File Manager’ in your WordPress hosting cPanel.
Once you have access to the files of your website, Now add the following line of code to your robots.txt file
User-agent: *
Disallow: /your-page/
You can use the user-agent line to target specific bots. To include all search engines, we use the asterisk sign.
Let’s say you wish to hide a blog post with the following URL:
https://example.com/2021/08/post-1/
This is how you’ll include this URL in your robots.txt file.
User-agent: *
Disallow: /2021/08/post-1/
Now save the changes and upload the file back to your site’s server.
There are some disadvantages of this method too.
Disadvantages
Please keep in mind that the robots.txt file is open to the public and anyone can access it and see if you are hiding some pages.
While the instructions in the robots.txt file are followed by most search engines, many other crawlers and bots may just ignore it.
These are the bots that crawl the internet in order to transmit malware, attack websites, or collect information such as email addresses.
That’s all, I hope that this article helped you learn How to hide a page in WordPress. You may also want to see our guide on How to add users to Google Analytics and the Best Drag and Drop page builders.
Hope you guys liked this blog post and If you really liked it please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter, Facebook, and Instagram.