1

Where and how would I be able to customize the login error messages?

"Error: The username <> is not registered on this site. If you are unsure of your username, try your email address instead."

and "Error: The password you entered for the username <> is incorrect. Lost your password?"

I've tried using this code, but nothing. Any help would be appreciated!

    global $errors;
    $err_codes = $errors->get_error_codes();

    // Invalid username.
    if ( in_array( 'invalid_username', $err_codes ) ) {
        $error = '<strong>ERROR</strong>: This email address is not registered. Please check or contact XXX for more information.';
    }

    // Incorrect password.
    if ( in_array( 'incorrect_password', $err_codes ) ) {
        $error = '<strong>ERROR</strong>: The password you provided is incorrect. Please try again or contact XXX for more information. ';
    }

    return $error;
}

add_filter( 'login_errors', 'my_custom_error_messages');```

2 Answers 2

3

I can't see your complete code... However, your code should look like this:

function my_custom_error_messages( $error ) {
    global $errors;
    $err_codes = $errors->get_error_codes();
 
    // Invalid username.
    // Default: '<strong>ERROR</strong>: Invalid username. <a href="%s">Lost your password</a>?'
    if ( in_array( 'invalid_username', $err_codes ) ) {
        $error = '<strong>ERROR</strong>: Wrong username.';
    }
 
    // Incorrect password.
    // Default: '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s">Lost your password</a>?'
    if ( in_array( 'incorrect_password', $err_codes ) ) {
        $error = '<strong>ERROR</strong>: Wrong password.';
    }
 
    return $error;
};
add_filter( 'login_errors', 'my_custom_error_messages' );

The code above has been tested and worked.

0

In addition to what @Tommy Pradana wrote, here's an array of some of the available error codes you can modify (found in the wp-login.php file):

array( 
    'empty_password',
    'empty_email',
    'invalid_email',
    'invalidcombo',
    'empty_username',
    'invalid_username',
    'incorrect_password',
    'retrieve_password_email_failure' 
);

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.