How to write Password Protected WordPress Posts

Once you publish a WordPress post or Page, by default it is visible to the public. In WordPress terms, this means a post with a Published status has a default visibility of Public.  You can change this setting by using the publish section of the post editor mode. Clicking the “Edit” link next to Visibility: Public reveals three radio buttons:

  • 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.


publish settings password


So we are going to talk about the Password protected option. When you’re done editing the post’s visibility, click the “OK” button. You should now see your post’s new setting, e.g., Visibility: Password Protected.

Remember: a setting change does not take effect until you click the “Publish” button (or “Update” if the post is already published.)

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:”


Only an Administrator, Editor, or the post’s Author can change a post’s password or visibility setting once set. WordPress stores this password in a browser cookie 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.

But WordPress will only track one password at a time. Therefore, if two posts use two different passwords, entering the password for post 1, then entering the password for post 2 means that revisiting post 1 (or any post which shares its password) will require the user to re-enter the password for post 1.

Hide Password Protected Posts

If you don’t want your password protected posts to show up on other places around your site, like on the home page or archive pages, there is a code segment you can add. To effectively hide them from these pages without affecting your pagination, place the following code in your theme’s functions.php:

[code languague=”php”] posts}.post_password = ” “;

// Decide where to display them
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’);


Password Protected Posts are more beneficial when you are conducting a learning environment for your school or institution, to display content only to your registered students.

Written by Sandeep Likhar

Sandeep Likhar is from India, where he is a blogger, eBook designer, and founder of LetsDnD. He has 6 years of experience in the industry as a Digital Publishing Expert and eBook Converter, providing services to authors, publishers, and distributors worldwide. He is proficient in converting books into various formats, such as HTML, epub, mobi, word, PDF, including all major online platforms like iTunes, Kobo, Kindle, CreateSpace, B&N, Smashwords, and more.

Comment Below