Support » Fixing WordPress » Password form not showing on protected page template, content just disappears

  • Resolved dave


    I’m trying to password protect a page with a custom template. I used the

      if ( !post_password_required() ) {
        ##the password-tested content##

    around the content I want protected, as suggested in other posts.

    The title is switched to “Protected: #title”, but my content only disappears and no password input form shows up. Any ideas how to get this to work? I feel like it’s almost there, but I’m not sure how to get it 100% working. Thanks in advance for any ideas!

Viewing 5 replies - 1 through 5 (of 5 total)
  • dave


    I ended up using this code:

    // Globalize $post
    global $post;
    // Test for password-protected page
    // Returns true if post is password-protected
    // and if the password doesn't match cookie
    if ( post_password_required( $post ) ) {
        GOES HERE
    } else {
        // Page isn't password-protected

    because I realized the code doesn’t automatically include the password input field.

    My question now is: What is the code to add the proper password input field?




    Ok, so after some more research and tweaking, I ended up with this code:

        <form action="<?php get_option('siteurl'); ?>/wp-login.php?action=postpass" method="post">
        <p>This page is password protected. Please enter your client password below:</p>
        <p><input name="post_password" id="<?php $label ?>" type="password" size="20" /><input type="submit" name="Submit" value="Submit" /></p>

    in the area where “Custom content that displays only when page is password protected goes here” is. The main thing I was looking for was the form action that would ask for the correct password (“postpass”).

    Hope this helps someone!

    Hi,thank you for sharing. But where I should put this code? In my template page?



    I think it’s easier if you use this
    <?php echo get_the_password_form(); ?>

    Note that the password form uses <siteurl>/wp-pass.php now, instead of wp-login.php?action=postpass.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Password form not showing on protected page template, content just disappears’ is closed to new replies.