How to protect your posts or pages with a Password

Dave Abargel,

Have you ever thought of creating a Private Post just for close friends or family? Or creating a post that is only for editors on your WordPress site?
As a Content Publishing Platform, WordPress comes with Basic Content Visibility Options, which most Novice Users ignore.
In this article we’ll show you how to Password Protect a page or post in WordPress.

While you write the post, there is an option called View, which by default is set to Public.
When you click Edit, you’ll see several options including Password protected or Private.

Visibility options

To perform this action simply Click on Password protected to add a Password to the post.
Only friends, family, or Users you shared your Password with will be exposed to the post.

A Private Post in WordPress is only visible to Users who are logged in with a User Level at the Editor or Administrator Level in WordPress.

The same process works well for WordPress Page Protection using a Password.

Hide Password Protected posts on the Home Page and Search Results

All your Password Protected posts may appear along with the rest of your posts on the Homepage, or in the Search Results on the site.
If you want to hide them completely, you can embed the following code in the function.php file of your WordPress site.

// 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 protected posts will not appear on the Home Page or on the site Search Results.
To post a Password Protected User – you can send the URL of the post, along with the password.

We hope we’ve been able to clarify how to protect your posts with a Password, easily and efficiently. If at anytime you have questions or need a helping hand,  uPress offers  24/7 VIP Customer Service.

Did you like the article? Sign up for the uPress newsletter and always stay up-to-date.

Dave Abargel

VP and founder of uPress, developer of Backend & Frontend, specializes in improving performance for WordPress websites, handling advanced security issues, and marketing on social networks. He is an active partner in a number of interesting projects in the field, such as WiPi, Enable, Greenicon, Speedom, and more.

  • You might be interested…

  • Leave a Reply

    Your email address will not be published. Required fields are marked *