编写自定义登录页面时,需要注意错误,否则WordPress会将页面重定向到/wp admin或wp login。php错误的密码或空凭据。请按照以下步骤解决此问题:--
请在主题的功能中使用以下内容。php文件:-
/**
* Function Name: front_end_login_fail.
* Description: This redirects the failed login to the custom login page instead of default login page with a modified url
**/
add_action( \'wp_login_failed\', \'front_end_login_fail\' );
function front_end_login_fail( $username ) {
// Getting URL of the login page
$referrer = $_SERVER[\'HTTP_REFERER\'];
// 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( get_permalink( LOGIN_PAGE_ID ) . "?login=failed" );
exit;
}
}
/**
* Function Name: check_username_password.
* Description: This redirects to the custom login page if user name or password is empty with a modified url
**/
add_action( \'authenticate\', \'check_username_password\', 1, 3);
function check_username_password( $login, $username, $password ) {
// Getting URL of the login page
$referrer = $_SERVER[\'HTTP_REFERER\'];
// 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\' ) ) {
if( $username == "" || $password == "" ){
wp_redirect( get_permalink( LOGIN_PAGE_ID ) . "?login=empty" );
exit;
}
}
}
// Replace my constant \'LOGIN_PAGE_ID\' with your custom login page id.
并在自定义登录页面文件中显示以下内容,以显示相应的错误:--
<div class="wp_login_error">
<?php if( isset( $_GET[\'login\'] ) && $_GET[\'login\'] == \'failed\' ) { ?>
<p>The password you entered is incorrect, Please try again.</p>
<?php }
else if( isset( $_GET[\'login\'] ) && $_GET[\'login\'] == \'empty\' ) { ?>
<p>Please enter both username and password.</p>
<?php } ?>
</div>