Today I will share you guys another WordPress snippet to filter or change error message in WordPress admin login area; this is useful when you want to change it to your own custom error message that you feel more informative, just add this short snippet in your theme functions.php file and done :)

Solution:

 PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
add_filter( ‘login_errors’, ‘rs_custom_login_error’ );
/*
* @desc    Filter WordPress admin error message
* @param str $message        Error message to be translated
*/
function rs_custom_login_error( $message ) {
    global $errors;
    if (isset($errors->errors['invalid_username']) || isset($errors->errors['incorrect_password'])) :
        $message = __(‘<strong>ERROR</strong>: Invalid username or password combination.’, ‘rys’) . ‘ ‘ .
        sprintf((‘<a title=”%2$s” href=”%1$s”>%3$s</a>?’),
        site_url(‘wp-login.php?action=lostpassword’, ‘rys’),
        __(‘Password Lost and Found’, ‘rys’),
        __(‘Lost Password’, ‘rys’));
    endif;
    return $message;
}

Solution 2:

 PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
add_filter( ‘login_errors’, ‘rs_custom_login_error’ );
/*
* @desc    Filter WordPress admin error message
* @param str $error Error message to be changed.
*/
function rs_custom_login_error( $error ){
    // Lets say you want to overwrite incorrect message.
    $pos = strpos( $error, ‘incorrect’ );
    if ( false === $pos  ) {
        // Overwrite error message.
        $error = “Wrong information”;
    }
    return $error;
}

If the two solutions above didn’t work try this one instead.

1
2
3
4
5
6
7
add_filter( ‘login_errors’, ‘rs_custom_login_error’ );
/*
* @desc    Filter WordPress admin error message
*/
function rs_custom_login_error(){
    return $error = “Oops!, sorry you have inputted wrong credentials.”;
}
Note: If you want to hide error message then simply return empty text.

0 comments:

Post a Comment

 
Top