在哪里以及如何自定义登录错误消息?
"E;错误:用户名(<&燃气轮机;未在此网站上注册。如果您不确定您的用户名,请尝试您的电子邮件地址"E;
和;错误:您为用户名输入的密码<&燃气轮机;不正确。丢失密码"E;
我试过使用这个代码,但什么都没有。任何帮助都将不胜感激!
global $errors;
$err_codes = $errors->get_error_codes();
// Invalid username.
if ( in_array( \'invalid_username\', $err_codes ) ) {
$error = \'<strong>ERROR</strong>: This email address is not registered. Please check or contact XXX for more information.\';
}
// Incorrect password.
if ( in_array( \'incorrect_password\', $err_codes ) ) {
$error = \'<strong>ERROR</strong>: The password you provided is incorrect. Please try again or contact XXX for more information. \';
}
return $error;
}
add_filter( \'login_errors\', \'my_custom_error_messages\');```
SO网友:Tommy Pradana
我看不到你的完整代码。。。但是,您的代码应该如下所示:
function my_custom_error_messages( $error ) {
global $errors;
$err_codes = $errors->get_error_codes();
// Invalid username.
// Default: \'<strong>ERROR</strong>: Invalid username. <a href="%s">Lost your password</a>?\'
if ( in_array( \'invalid_username\', $err_codes ) ) {
$error = \'<strong>ERROR</strong>: Wrong username.\';
}
// Incorrect password.
// Default: \'<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s">Lost your password</a>?\'
if ( in_array( \'incorrect_password\', $err_codes ) ) {
$error = \'<strong>ERROR</strong>: Wrong password.\';
}
return $error;
};
add_filter( \'login_errors\', \'my_custom_error_messages\' );
以上代码已经过测试和使用。