We can also use the filter wp_login_errors
available in wp-login.php
to do the above. Using the same filter you can customize other error messages too like registration
, checkmail
etc.
Use the below code in the active theme’s functions.php
file
add_filter( 'wp_login_errors', 'override_incorrect_password_msg', 10, 2 );
function override_incorrect_password_msg( $errors, $redirect_to ) {
if( isset( $errors->errors['incorrect_password'] ) ) {
$errors->errors['incorrect_password'][0] = 'Your new message';
}
return $errors;
}
And if you want to get hold of the username at this time you can do that by using another hook ie: wp_login_failed
add_action( 'wp_login_failed', 'wpse_end_login_fail' );
function wpse_end_login_fail( $username ) {
echo $username;
// Go on with what you want to do with the login failed username
}
The above will give you the username
You can see the above set of codes in action in the below image. You can see the username we got using the hook in the top left corner of the image/screenshot