When I try to add password protection a custom page template it doesn't work. It works properly when I'm logged in. It shows the password field and after entering it, I see the protected content.

However, when I'm logged out, it displays all of the content and no password field.

How do I make it so that the content only displays once someone has entered the password?


This is what I have:

 * Template name: Customize
 * @package jessicasmith


        while ( have_posts() ) : the_post();

            if ( post_password_required( $post ) ) { ?>

                <div class="wrapper password">

                    <?php echo get_the_password_form(); ?>


            <?php } else {

                get_template_part( 'template-parts/content', 'custom' );


        endwhile; // End of the loop.


1 Answer 1


Post_password_required returns false in two cases:

  1. No password required

  2. Cookie with password present

So, once you have entered the password and logged out, the cookie will still be present and you get access to the content.

(When I go to your site, without login or password, I get the password field just as I should)

  • Thanks. This is so strange because I clear my cookies every time when testing. But now when I try it - it works! lol Commented Jan 13, 2017 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.