how to use password on WordPress protected posts?

how to use password on WordPress protected posts?

You may need to write some posts and hide them from all the team or protect them to be invisible on posts or on archive. You can use this trick on visitors too. When you add protected password on the post, no visitor can read it without this password. This can be useful for member only pages or pages that are only meant for a certain audience. The good news is WordPress makes it quite easy to set up a password protected posts or pages.

Visibility options in WordPress


When you check the part of “Publish” in your post, you can see option called “Visibility” and next to it “Edit” button. The visibility is public by default and by pressing edit you can see more.

  • Public is selected by default.
  • Checking Password protected reveals a text field for entering a password, that will be required to view that post. The password is limited to 20 characters.
  • Checking Private makes your post visible only to your site’s Users with the role of Administrator or Editor.

When you’re done, click the “OK” button. You should now see your post’s new setting. Remember: a setting change does not take effect until you click the “Publish” button (or “Update” if the post is already published.)

Authority of password changing

Only an Administrator, Editor, or the post’s Author can change a post’s password or visibility setting. To do so, use the same previous steps.

The Visibility “Edit” link is also a good way to reveal a forgotten post password.

Password Protected Posts

WordPress displays a password-protected post differently. It makes these changes to the post’s:

  • Title: Adds the text “Protected: ” before the post Title.
  • Excerpt: Instead of the post Excerpt, prints this text: “There is no excerpt because this is a protected post.”
  • Content: Instead of the post Content, prints a password form with this text: “This post is password protected. To view it please enter your password below:”

Many protected posts

WordPress stores the password in the browser cookies so readers don’t have to re-enter passwords if they visit the same page multiple times. Furthermore, if multiple posts use the same password, the reader will only have to enter the password once to access every post.

WordPress will only track one password at a time. Therefore, if two posts use two different passwords, entering the password for post A, then entering the password for post B means that revisiting post A will require the user to re-enter the password for post A.


Hiding Password Protected Posts Completely From Homepage and Archives

Protected password posts can appear in the homepage among other posts. So if you need to hide them completely from your site, you can add the below code in “function.php” file in the themes 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’);

Now, your protected posts will not appear in the site’s homepage or archives. You can send the post’s URL to users with the password.

Leave a Reply

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