将以下内容添加到函数中。php文件。
function my_custom_error_messages() {
global $errors;
$err_codes = $errors->get_error_codes();
// Invalid username.
if ( in_array( \'invalid_username\', $err_codes ) ) {
$error = \'<strong>ERROR</strong>: Custom Message Here\';
}
// Incorrect password.
if ( in_array( \'incorrect_password\', $err_codes ) ) {
$error = \'<strong>ERROR</strong>: Another Custom Message Here\';
}
return $error;
}
add_filter( \'login_errors\', \'my_custom_error_messages\');
如果只需要一条消息,可以为每条消息编写单独的错误消息,也可以合并if语句。像这样。
if ( in_array( \'invalid_username\', $err_codes ) || in_array( \'incorrect_password\', $err_codes ) ) {
$error = \'<strong>ERROR</strong>: Custom Message Here\';
}