How to protect your posts or pages with a password

Read more about these topics!

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.

hello world!

Related Posts

Migrate WordPress Website from Previous Host

Ready to move to uPress? This user-friendly guide will teach you how to migrate your site with our Auto Migration Tool - you can complete the process and be up and running in 24 hours!
Read More

The Complete WordPress Security Guide Part 3

Ready for the big guns? Parts 1 and 2 of this security-based miniseries walked you through what needs to be done and how to do it. Part 3 is advanced information for developers and WordPress admin experts to build and maintain secure WordPress sites.
Read More

The Complete WordPress Security Guide Part 2

Part 1 of this security-based miniseries discussed the vital foundations that you need to lay to set up a secure website, but it doesn’t end there. Part 2 discusses tips to help you to keep your WordPress site secure long-term from updating non-active plugins and themes to preventing and blocking bad bots.
Read More

Get managed WordPress hosting that gives you

simplicity, accessibility, speed and security.

And no worries.

Find the plan for you.

Explore Plans