I’m using wp_login_form()
to display login form in a jQuery dialog window.
If user enters wrong password, the user is taken to the backend. I don’t want that. Is there a way to notify user that he entered wrong password and still remain on the same page?
Before wp_login_form()
came I was using a plugin. I’m kind of hoping I can avoid using a plugin for this.
My code:
wp_login_form( array(
'label_remember' => __( 'Remember me' ),
'label_log_in' => __( 'Login' )
) );
wp_login_form()
creates a form with an action attribute ofsite_url/wp-login.php
, which means that when you click the submit button the form is posted tosite_url/wp-login.php
which ignores redirect_to on errors (like wrong password) so in your case either go back to using a plugin or recreate the whole login process and that way you will have control on errors, take a look at Check for correct username on custom login form which is very similar question.I came here from google. But the answer didn’t satisfy me. I was looking for a while and found a better solution.
Add this to your functions.php:
The current method I am using to deal with all of the issues outlined here works great even with blank username/password and doesn’t rely on javascript (though the js could be good along with this).
The key is this filter to change how a blank username/password is treated:
You can take this a step further and completely replace wp-login.php by redirecting users to your custom login page and use that page for the login_failed redirect also. Full code:
Customize and add these to add your logo to the wp-login page for password recovery:
Login logo css:
EDIT: I just implemented this on another site form scratch, and found the above “step further” to be more complete, and fixed small syntax errors in the “add_actions”. Added some comments and a method to automatically add the login form to login page without a separate template file. The login form method should work in most instances, since it is attached to “the_content”, it could cause and issue if you have more than one loop on the login page, just use a page-login.php template in that case.
A solution for Szczepan HoÅyszewski’s point about empty fields in the accepted solution, the following jQuery will prevent going to the standard wp-login page: (add to login page template or footer.php)
The following worked for me. Both of these hooks can be found within the function
wp_authenticate
withinwp-includes/puggabel.php
.authenticate
filter if the login form is missing the username or password.wp_login_failed
action if the authentication of the supplied username and password has failed.One addition to Alexey’s answer. You can add a jquery function to check that one of the fields is not blank. That way the form will not submit unless there is something to check, preventing WordPress from redirecting to /wp-login.php.
Still not sure how to fix the forgot password aspect