Hi @master1234321,
I hope you are keeping well and thank you for reaching out to us.
The following workaround should help you with customizing the login error messages.
<?php
remove_filter( 'authenticate', 'wp_authenticate_username_password' );
add_filter( 'authenticate', 'custom_error_formi_loginScreen', 20, 3 );
/**
* Remove WordPress filer and write our own with changed error text.
*/
function custom_error_formi_loginScreen( $user, $username, $password ) {
if ( is_a($user, 'WP_User') )
return $user;
if ( empty( $username ) || empty( $password ) ) {
if ( is_wp_error( $user ) )
return $user;
$error = new WP_Error();
if ( empty( $username ) )
$error->add( 'empty_username', __('<strong>ERROR</strong>: The username field is empty.' ) );
if ( empty( $password ) )
$error->add( 'empty_password', __( '<strong>ERROR</strong>: The password field is empty.' ) );
return $error;
}
$user = get_user_by( 'login', $username );
if ( !$user )
return new WP_Error( 'invalid_username', sprintf( __( '<strong>ERROR</strong>: Invalid username.' ) ) );
$user = apply_filters( 'wp_authenticate_user', $user, $password );
if ( is_wp_error( $user ) )
return $user;
if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) )
return new WP_Error( 'incorrect_password', sprintf( __( '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect.' ),
$username ) );
return $user;
}
To change the error message mentioned in the screenshot provided, please replace the following from the above code.
<strong>ERROR</strong>: Invalid username.
The code could be added using a mu-plugin. I hope the following guide helps you further: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
Please test the code on a staging or development environment before pushing it to the live website.
Kind Regards,
Nebu John