I render login form on my header template using this code:
<?php wp_login_form($args); ?>
When I pass proper credentials, it redirect me to homapage and all seems to be fine, but when I put wrong login or pass, it redirect me to the folowing url:
http://localhost/wordpress/wp-login.php
So the question is how I can output errors on the same page , and prevent redirection to the wp-login
? I try to find solution but didnt have any results. Thanks!
Add this to your 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;
}
}
This code redirects to the same page as the user tries to log in from. Change $referrer
for another page.
Hope it will works for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.