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 about private pages in WordPress and how to create one using a password.
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.
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.
Migrate to uPress within 24 hours
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.
// 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');
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.
As managed WordPress hosting experts, we know what we're talking about, whether you need simple information about private and password protected pages, or you want the whole lowdown on security and what you can do to protect your site. You can trust us with the entire gamut of WordPress questions, so the only one left is... why aren't we hosting your WordPress site yet? Click below and join us.