My custom login form redirects to the wp-admin login when an user doesn’t manage to guesses his/her credentials right. How can I manage to redirect the user to the current form instead? And of course show the proper errors?
Here is the code: (same as on WordPress manual)
$args = array(
'echo' => true,
'redirect' => site_url( $_SERVER['REQUEST_URI'] ),
'form_id' => 'loginform',
'label_username' => __( 'Username' ),
'label_password' => __( 'Password' ),
'label_remember' => __( 'Remember Me' ),
'label_log_in' => __( 'Log In' ),
'id_username' => 'user_login',
'id_password' => 'user_pass',
'id_remember' => 'rememberme',
'id_submit' => 'wp-submit',
'remember' => true,
'value_username' => NULL,
'value_remember' => false );
wp_login_form( $args );
While coding a custom login page, one needs to take care of the errors, else WordPress would redirect the page to /wp-admin or wp-login.php on wrong passwords or empty credentials. Please follow the below to solve this issue:–
Please use the below in your theme’s functions.php file:-
and the below in the custom login page file to show the corresponding errors:–
Did you tried echoing the
this one works fine, I’ve used it succesfuly
Update
For redirect on login failure, you gotta use wp_login_failed hook, and some custom code to redirect user to desires page with proper warning message.
And if you are redirecting to some template, you can easily get login_error and display it accordingly.
Thank you to Maruti for your comment, it’s really helped me with the exact same issue!
Where he has written:
“and the below in the custom login page file to show the corresponding errors…”
does somebody know where I can find the login page file? I have a feeling this is a silly question, but I’ve looked everywhere I can think of, and can’t find where to add the div error code?
Thanks for any response!