我知道这已经在其他几个帖子中讨论过了,但似乎没有一个帖子对这个问题有正确的答案/解决方案。我尝试使用其他帖子中提到的所有建议功能,但似乎都不起作用。当引入错误的密码时,什么都不会发生(只是标准重定向到同一页面),唯一接近答案的是以下代码toscho 在此线程上-Add error message on password protected page 但不幸的是,无论是否尚未引入密码,或您一登录页面,错误消息就会显示:
<?php
add_filter( \'the_password_form\', \'wpse_71284_custom_post_password_msg\' );
function wpse_71284_custom_post_password_msg( $form )
{
// No cookie, the user has not sent anything until now.
if ( ! isset ( $_COOKIE[ \'wp-postpass_\' . COOKIEHASH ] ) )
return $form;
// Translate and escape.
$msg = esc_html__( \'Sorry, your password is wrong.\', \'your_text_domain\' );
// We have a cookie, but it doesn’t match the password.
$msg = "<p class=\'custom-password-message\'>$msg</p>";
return $msg . $form;
}
?>
非常感谢您的时间和投入。