Using WordPress ‘login_errors’ PHP filter

The login_errors WordPress PHP Filter allows you to modify the error messages displayed above the login form.


add_filter('login_errors', 'your_function_name');
function your_function_name($errors) {
    // your custom code here
    return $errors;


  • $errors (string) – The login error message to be displayed.

More information

See WordPress Developer Resources: login_errors


Customize the Login Error Message

Change the default error message for a more user-friendly one.

add_filter('login_errors', 'change_login_error_message');
function change_login_error_message($errors) {
    $errors = 'Oops! Something went wrong. Please try again.';
    return $errors;

Hide Login Error Message

Hide the error message for security purposes.

add_filter('login_errors', 'hide_login_error_message');
function hide_login_error_message($errors) {
    $errors = '';
    return $errors;

Display a Custom Error Message for Invalid Username

Show a custom error message when the username is invalid.

add_filter('login_errors', 'invalid_username_error_message');
function invalid_username_error_message($errors) {
    if (strpos($errors, 'Invalid username') !== false) {
        $errors = 'The username you entered is incorrect.';
    return $errors;

Display a Custom Error Message for Incorrect Password

Show a custom error message when the password is incorrect.

add_filter('login_errors', 'incorrect_password_error_message');
function incorrect_password_error_message($errors) {
    if (strpos($errors, 'The password you entered') !== false) {
        $errors = 'The password you entered is incorrect.';
    return $errors;

Add a link to the “Forgot Password” page below the error message.

add_filter('login_errors', 'add_forgot_password_link');
function add_forgot_password_link($errors) {
    $errors .= ' <a href="' . wp_lostpassword_url() . '">Forgot Password?</a>';
    return $errors;