19

took a look at the questions but I couldn`t find a similar one.

I need to change the custom error messages that are displayed when user tries to login with a wrong username or password.

Like, change this: "ERROR: The password you entered for the username %1$s is incorrect. Lost your password?" to this "Wrong information" (just an example)

I tried to use the "add_filter" but I`m not familiar with it, so, any help will be appreciated! Thanks

  • For what it's worth, the comment above by user20986 is spam. It takes you to a page that tells you that your flash software is out of date and needs to be updated. Recommend that admins remove the comment by user20986 – leromt Jan 30 '19 at 15:07
21

you can do that using login_errors filter hook and here is how:

add_filter('login_errors','login_error_message');

function login_error_message($error){
    //check if that's the error you are looking for
    $pos = strpos($error, 'incorrect');
    if (is_int($pos)) {
        //its the right error so you can overwrite it
        $error = "Wrong information";
    }
    return $error;
}

update:

i just tested the code and it works fine just pasted the code in my theme's functions.php file without changing anything with the .po file

enter image description here

  • Just to make everything clear, I should replace 'incorrect' with the error string? By the way, thanks for your answer! – Vitor Argos Aug 5 '11 at 22:07
  • Just tried this way and it doesnt work, but Im not sure if the wordpress .po file is overwriting the text. Any ideas? – Vitor Argos Aug 5 '11 at 22:10
  • the text from WordPress.po is served before that filter hook is fired, and no you don't have to change incorrect, its checking if the error message contains that word. – Bainternet Aug 5 '11 at 22:15
  • I tried to put this to work but I couldn`t. I actually even tried to remove the conditional part, so it should return the text in the $error variable right? But it has no effect. Digging the .po file I saw that the messages I want to overwrite are located in the wp-includes/user.php file like: "<strong>ERROR</strong>: The username field is empty." – Vitor Argos Aug 5 '11 at 22:37
  • @Vitor you are doing something wrong, there is no need to touch the .po file, i updated my answer. – Bainternet Aug 6 '11 at 0:03

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