我使用以下代码在我的标题模板上呈现登录表单:
<?php wp_login_form($args); ?>
当我传递正确的凭据时,它会将我重定向到homapage,一切似乎都没问题,但是当我输入错误的登录信息或通过时,它会将我重定向到以下网址:
http://localhost/wordpress/wp-login.php
所以问题是如何在同一页面上输出错误,并阻止重定向到wp-login
?我试图找到解决方案,但没有任何结果。谢谢!
答案 0 :(得分:2)
将此添加到你的functions.php:
add_action( 'wp_login_failed', 'my_front_end_login_fail' ); // hook failed login
function my_front_end_login_fail( $username ) {
$referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from?
// if there's a valid referrer, and it's not the default log-in screen
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
wp_redirect( $referrer . '?login=failed' ); // let's append some information (login=failed) to the URL for the theme to use
exit;
}
}
此代码重定向到用户尝试登录的同一页面。
将$referrer
更改为其他页面。
希望它适合你。