How to translate wordpress error message
Hello, Good Morning! I am having a problem and I am not finding the variable to be able to solve, I have a site in WP and when it tries to log in and neither the password nor the email exist it returns me the error message: ERROR: the username or password you entered is incorrect. Lost your password? I tried to locate this phrase in wp-login.php but I did not find it there, could you help me? Obs.: I tried to use loco translate but he doesn't find that phrase!
Edit do test that I am trying to make the messages appear only on the login page.
Functions.php
function erroLogin(){
add_filter( 'login_errors', 'rs_custom_login_error' );
function rs_custom_login_error(){
return $error = "Informações não existem ou estão erradas!";
}
}
Page.php
<?php if ( is_page( 'login' ) ) { ?>
<?php erroLogin(); ?>
<?php } ?>
And I tried that other way too.
Functions.php
<?php if ( is_page( 'login' ) ) { ?>
add_filter( 'login_errors', 'rs_custom_login_error' );
function rs_custom_login_error(){
return $error = "Informações não existem ou estão erradas!";
}
}
But it hasn't worked out yet
3 answers
Searches your theme for the file functions.php
then puts this snippet
add_filter( 'login_errors', 'rs_custom_login_error' );
/*
* @desc Filtro da mensagem de erro do admin do WP
*/
function rs_custom_login_error(){
return $error = "Sua mensagem de erro vai aqui";
}
Here are other snippet options that you can use to customize this message. http://www.sutanaryan.com/2012/09/how-to-filter-or-change-wordpress-admin-error-message/
Option direct by admin area. Access A functions.php as picture
Then put this code and an update file
add_filter('login_errors', create_function('$no_login_error', 'return "The user name and password is incorrect."'));
If it still doesn't work, paste this code into the file. The first is for the new message, and the second to hide the default message
function login_error_override()
{
return 'The user name and password is incorrect.';
}
add_filter('login_errors', 'login_error_override');
add_filter('login_errors', create_function('$a', 'return null;'));
Reference source: https://whatswp.com/change-wordpress-login-error-message /
I managed to solve my problem, follow the code in case someone needs this solution:
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 = "Um ou mais campo estão em branco ou dados não existem!";
}
return $error;
}
Source from which I found the answer: https://wordpress.stackexchange.com/questions/25099/change-login-error-messages