How to protect your posts or pages with a password

Omer, COO

September 13, 2020

How to create a private page in WordPress

Have you ever wondered if there’s a way to publish content on your WordPress blog that’s only visible to certain people, instead of sharing every single post with the whole world? 

If so, we’re happy to tell you that it’s possible. You just need to learn what is a private page in WordPress and how to create one using a password. 

What is a private page in WordPress?

Many people ask what is a private page in WordPress, either because they see the options on their WordPress editor or they hear other people talking about it. A private page in WordPress is essentially a page or post that can only be read by selected visitors to your site. One of the easiest ways to make a private page in WordPress is by using a password.

What is a private page in WordPress that’s password-protected?

As part of its content management system, WordPress comes with a number of basic content visibility options, but most novice users don’t notice them. 

While you write a new post or page and go to publish it, you’ll see a heading “Visibility”. By default, this is set to public, but if you click Edit then several other options will appear. One of them is “Password protected”.

When you click “Password protected,” you’ll see an option to add a password to the post. Once you’ve done this, only visitors who have the right password will be able to read the post. 

If you set your WordPress post to Private, then only users who have Editor or Admin status will be able to read it. 

You can do the exact same thing for WordPress Pages.

How to hide WordPress posts entirely

Although only selected visitors can read your private or password-protected posts, they still show up on your homepage and in search results, even though the average guy on the internet can’t read the actual content. 

But there is a way to hide these posts entirely so that they don’t even show up in search or on the homepage. It does involve a little code, but our step-by-step guide makes it easy.

  1. Copy the code below.
// 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');
  1. Go to your WordPress menu and hover over “Appearance.” In the menu that appears, click “Editor.”
  2. On the right-hand side of the screen, you’ll see “functions.php” or “Theme functions.” Click this to go to the code editor. 
  3. Now paste the code that you copied into the code editor and click Save.

That’s all it takes. Now your private and protected posts will be totally hidden.

If you want to share a password-protected post with someone, just send them the URL of the post together with the password they need to access it. 

Now you know what is a private page in WordPress and how to create one easily. 

If you have any questions or need a helping hand, contact uPress’ 24/7 VIP customer service.

Click on the tags below to find more blogs about the topic!

hello world!

Get managed WordPress hosting that gives you

simplicity, accessibility, speed and security.

And no worries.

Find the plan for you.

Explore Plans
envelopephone-handsetmap-marker