Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to translate the above message which appears on invalid username.

I know the answer is very similar to the one proposed here by I cannot find the exact handler.

Thank you.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

In the en_GB version of the .mo translation file, this string is available:

<strong>ERROR</strong>: Invalid username. <a href=\"%s\" title=\"Password Lost and Found\">Lost your password</a>?

and the reference is from wp-includes/user.php on line 93. I found this using Poedit and searching using Ctrl + F.

From line 93 we get the following code:

return new WP_Error( 'invalid_username', sprintf( __( '<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?' ), wp_lostpassword_url() ) );

Which means you should write a function for your functions.php hooking into invalid_username like so:

add_filter( 'wp_login_errors', 'override_incorrect_username_message', 10, 2 );
function override_incorrect_username_message( $errors, $redirect_to ) {
    if( isset( $errors->errors['invalid_username'] ) ) {
        $errors->errors['invalid_username'][0] = 'Your new translated message';
    }

    return $errors;
 }

You can hunt around in wp-includes.php for other similar error messages which you can fix in a similar way.

share|improve this answer
    
many thanks for your answer, unfortunately it does nothing in my case.. I still search it, thank you. –  p.a. Dec 27 '13 at 19:38
    
I also try to add the message in my theme's .mo file but to no avail. –  p.a. Dec 27 '13 at 19:52
    
I found a typo in your answer. Correcting it above. It now works. Thanks a lot! –  p.a. Dec 27 '13 at 20:17
    
Oops! Yeah. Thanks for that. An oversight on my part. Glad it works. –  Strap1 Dec 28 '13 at 0:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.