How to Password Protect WordPress Page or Website?

Content is curated for the sole purpose of being read by the visitors. But, what happens when you don’t want them to read/reach a certain post or page? Password protect them, as simple as that.

In this tutorial, we will find out, “How to password protect WordPress pages/posts.” The method is universally applicable to posts/pages of a WordPress website. There can be many scenarios where an author, editor or the site owner want to protect a post/page.

The password protects page than can be shared with members or other people who can utilize the information for their benefit. Many websites with membership based or paid subscription would want only to share information with a selected few. Password protecting web pages/posts can help you take full control of what anyone sees.

If you are looking for a full-blown membership control, then this trick is not for you. You might want to invest in a membership plugin.

For those, who are looking for, “How to password protect WordPress page/posts”, let’s look at the steps that can help you achieve the privacy.

How to password protect WordPress Page

When writing WordPress posts or pages, there is a small “Publish” section on the right-hand side of the editor. Check out the image below to get a grasp of what I am conveying.

publish

As you can see in the above image, there is an option, “visibility.” Visibility means a simple way to control who can see the post when published.

Currently, the visibility plugin offers three options.

  • Public: The post/page can be seen by anyone who visits the website.
  • Password Protected: Password protects the post/page. Visitors with a password can view the page/post.
  • Private: Private is a state where the page/post is not visible to anyone. The private post is only visible to logged in users such as writer, editor or any other role that is set to have private post visible.

visibility-options

Out of the three options available, the only option that you should care about is the  “Password protected.”

Once, you click the “password protected” option, a small input box will open, asking you to input the password.

password-protected-field

The last step is to put a password in the input box and click “OK”.

And, we are done!

Getting Rid of All the Password Protected Page From The HomePage and Archives

Whenever you password protect a page or post, it still appears on your homepage or worse on the archives page.

There is a workaround that enable the webmaster to a complete hide the password protected pages from being indexed on the homepage or the archives page.

The below snippet does the job. All you need to do is copy-paste the following snippet in functions.php file.

// 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');

With the above code, all your password protected pages/posts will be kept hidden from the homepage.

Using Smart Passworded Pages For Better Configurability

Smart Passworded Pages is a smart way to password protect your pages. The plugin provides a central page login for any client or visitor. This centralized login enables the pages or a bunch of pages to be accessed by the client without entering the password now and then.

If you put a password on a parent page, then all the child pages will also be password protected. The idea is to provide a seamless experience for both the webmasters and the client.

And, if the client opens the child page with the password, all the related child pages, and the parent pages will be unlocked.

Adding a password field to a parent page is simple as adding a shortcode.

By adding, [smartpwpages], you can add a password field. The password field is customizable, and you can customize it according to your site theme.

Wrapping Up

Protecting web pages or posts is an essential requirement for many websites. Many websites run their business with the concept of providing vital information to clients who subscribe and pay for them. The form of service is commonly known as subscription and is seen in magazine websites.

Manually password protecting and hiding from the homepage and archives can give you a great good head start, but if you are planning to start a full-blown membership website, a membership plugin could be more useful.

If you liked the article, don’t forget to comment below and share it on social media platforms!

Editorial Staff
mail@85ideas.com

Editorial Staff at 85ideas is a team of WordPress experts led by Brian Harris. Here to share amazing tuts, guides and collections.

1Comment
  • Alt Rajapoker88
    Posted at 03:45h, 30 August Reply

    What’s up all, here every one is sharing these know-how, thus it’s noce to red this webpage, and
    I used to go to see this weblog every day.

Post A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.