• Hi,

    As many of you know, when using the wordpress standard password protection for pages, there is no error message when password is not correct, it just redirects to the same login page.

    I went through tens of topics in several forums and I couldn’t identify a correct way of displaying a simple “Password incorrect, please try again” message. Is there simple code that I can type in my functions.php to display an error message rather than the standard redirect to the same login page?

    Many thanks,
    Adrian

Viewing 2 replies - 1 through 2 (of 2 total)
  • This might be of use, add it to your functions.php file:

    <?php add_filter( 'the_password_form', 'custom_password_form' );
    function custom_password_form() {
    	global $post;
    	$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
    	$output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
    	<p>' . __("This section of the site is password protected. To view it please enter your password below:") . '</p>
    	<p><label for="' . $label . '">' . __("Password:") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Submit") . '" /></p>
    	</form>';
    
           if (isset($_COOKIE['wp-postpass_' . COOKIEHASH])
     and $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password){ ?>
       		<p style="color:#C00;">Password Invalid, please try again.</p>
    
    <?php } else { ?>
    
     <?php } ?>
    	<?php return $output;
    } ?>
    Thread Starter aitsatur

    (@aitsatur)

    Thank you for your reply @graphicscove but unfortunately after using your snippet, the sentence ‘Password Invalid, please try again’ appears above the form as soon as I open the password protected page(without having written anything in the password field)

    Also, when submitting a wrong password or even the correct one, it redirects to the 404 error page – Not found

    Any ideas?

    Many thanks,
    Adrian

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to display error message when password is wrong in password protected pages’ is closed to new replies.