How to Password Protect a WordPress Page or Post – A Beginner’s Guide

Not all pages or posts are mandatory to be shared with everyone. There might be times when you want to or have to protect your post or page and allow only specific users to use it. Therefore, if you do not want to make some of your areas in WordPress public, that is completely fine! Some contents can be restricted so that some of your users cannot view it publicly. In fact, you can even password protect WordPress site as you please. But how do we password protect a WordPress Page or post?
In this article, I will guide you all through step by step on how to password protect a WordPress page and post. Let’s get started…
If you looking for a more detailed instruction then continue reading the article.
How to password protect a WordPress page?
By default, WordPress allows us to protect our selected pages using a password. To do so, you have to simply follow some easy steps as given below.
Firstly, navigate to Pages>> All Pages. Then, hover over the page you want to password protect, and click on the edit option. After that, on the right-hand side of the text editor, you can see the option for the selecting the visibility. Here, you have the options to make your page public, password protected, or completely private.
Select the password protected option and then you will be provided with the password field. Create a password that is easier for you to remember and then click on the OK button.
And, that is it. Your password protected page can be viewed by only those users with whom you share the password.
How to restrict your WordPress post?
The process is similar to that of pages. Simply, go to Posts>> All Posts and follow the steps given above. Or you can also hover over your required posts. Then, Click on Quick Edit. You can then create a password. Make sure that you click on the update or save (if it is a new post) button to save the changes.
How to Password Protect Your Entire WordPress Site?
Like I mentioned earlier, along with protecting your post contents and pages with passwords, WordPress also allows us to password protect an entire WordPress site. For restricting access to your WordPress site using a password you can simply follow the given steps below.
First, install and activate the plugin. For the purpose, I recommend Password Protected plugin. It is a free and a popular plugin. Thus, you can easily find it on WordPress.org.
Upon the activation, go to Settings>> Password Protected so as to configure the plugin.Then on this page, first, checkmark the password protected status to enable it. Next, you can select the specific group of users you want to allow to log in to your website. Once done, click on Save Changes.
How to hide your password protected posts from homepage and archives?
Your password protected WordPress page or post may still appear on the homepage or the archives of your website. So, here’s how you hide them completely.
First, go to your WordPress dashboard. Then, navigate to Apeearance>> Editor. On the right-hand side, you will see functions.php under Themes File. You just need to add the code to it as shown in the image below:
Here is the code to add to your theme’s functions.php.
// To Hide protected posts function exclude_protected($where) { global $wpdb; return $where .= " AND {$wpdb->posts}.post_password = '' "; } // Where to display protected posts function exclude_protected_action($query) { if( !is_single() && !is_page() && !is_admin() ) { add_filter( 'posts_where', 'exclude_protected' ); } } // Action to queue the filter at the right time add_action('pre_get_posts', 'exclude_protected_action');
And that is it. Your password protected posts or pages will no more appear on your website’s homepage or archives. However, if you want some of your users to see it, then you can just send them the post’s URL with the password.
Wrapping it up!
All in all, protecting a website’s pages and posts or even the website sometimes becomes very crucial. And as always, WordPress has a solution for this as well. WordPress provides you with the complete power to control the visibility of the website’s pages and posts. Thus, you are the one who decides who sees what in your website. Whether you want to password protect some selected individual posts or an entire website, the choice is all yours!
Hopefully, this article helped you all in protecting your web pages, posts or website with a password. If so, you may also like to check out our other articles:
- How to Start a News Website in WordPress using ColorMag
- What is WordPress iFrame? How to Embed iFrame in WordPress?
- How to Add Rich Snippets to WordPress: Step-by-Step Guide For Beginners