WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have made a login form on the front-end of my site using wp_login_form(). However, when the user types in an incorrect username/password they are redirected to the wp-admin login form.

How can you instead display any error messages above the login form? Ideally, I don't want the user to ever have to see the Wordpress admin section.

I have tried using the redirect_invalid_login() hook but this doesn't seem to work?

share|improve this question
I believe this questions was answered here, wordpress.stackexchange.com/questions/15633/… – Wyck Aug 9 '12 at 0:02
And on that question wordpress.stackexchange.com/questions/14692/… – fdsa Aug 9 '12 at 2:12
up vote 5 down vote accepted

just add the following code to your function.php. it will redirect back user from where the login form is submitted.

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
share|improve this answer
how can we get errors like invalid passowrd or invalid username etc...??? – vrajesh Jun 26 '15 at 6:29

Here is what I did for anyone who has the same problem...

You can use the wp_login_failed hook as mentioned here, however this won't work if the user clicks login without entering a username and password.

To cover all errors you can copy the wp_authenticate() function located in wp-includes/pluggable.php and paste this in your themes functions.php file.

function wp_authenticate($username, $password) {
    $username = sanitize_user($username);
    $password = trim($password);

    $user = apply_filters('authenticate', null, $username, $password);

    if ( $user == null ) {
        $user = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Invalid username or incorrect password.'));

    $ignore_codes = array('empty_username', 'empty_password');

    if (is_wp_error($user) && !in_array($user->get_error_code(), $ignore_codes) ) {

        // Put your code here


    return $user;

You can then add you own code within if (is_wp_error($user) ... ) {.

share|improve this answer
I tried this but get Fatal error: Cannot redeclare wp_authenticate() (previously declared – Chris Jul 7 '14 at 11:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.