Styling my own password protected page, how to deal with wrong password?

This worked for me adding this code in functions.php:

add_filter( ‘the_password_form’, ‘wpse_71284_custom_post_password_msg’ );

/**

  • Add a message to the password form.

  • @wp-hook the_password_form

  • @param string $form

  • @return string
    */
    function wpse_71284_custom_post_password_msg( $form )
    {
    // No cookie, the user has not sent anything until now.
    if ( ! isset ( $COOKIE[ ‘wp-postpass‘ . COOKIEHASH ] ) )
    return $form;

    // Translate and escape.
    $msg = esc_html__( ‘La contraseña es incorrecta o ya ha sido utilizada.’, ‘your_text_domain’ );

    // We have a cookie, but it doesn’t match the password.
    $msg = “$msg

    “;

    return $msg . $form;
    }

add_action(‘init’, ‘myStartSession’, 1);
add_action(‘wp_logout’, ‘myEndSession’);
add_action(‘wp_login’, ‘myEndSession’);
function myStartSession() {
if(!session_id()) {
session_start();
}
}
function myEndSession() {
session_destroy ();
}

if ( post_password_required() ) {
$session_id = ‘wp-postpass_’ . get_the_ID();
//onload
$current_cookie = wp_unslash($COOKIE[ ‘wp-postpass‘ . COOKIEHASH ]);
//get old cookie
$old_cookie = isset( $_SESSION[ $session_id ] ) ? $_SESSION[ $session_id ] : ”;
//set new session
$_SESSION[ $session_id ] = $current_cookie;
if ( $current_cookie != $old_cookie && !empty( $old_cookie ) ){
error_notification(‘Error! Authentication failed!’);
}
}
?>