wordpress login failed redirect url does not work properly

In my wordpress project i created a front end log in for users and when user enters a wrong log in information it must redirect the login failed attachment with the url. Below code does it for the first time and then it append to the url continuously when trying to log in. How can i limit this.

add_action('wp_login_failed', 'my_front_end_login_fail'); 

    function my_front_end_login_fail($username){
        // Get the reffering page, where did the post submission come from?
        $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')){
            // let's append some information (login=failed) to the URL for the theme to use


              wp_redirect($referrer . '&login=failed'); 

        exit;
        }

    }

Any helps would be appreciated.

Related posts

Leave a Reply

1 comment

  1. try this code

    add_action('wp_login_failed', 'my_front_end_login_fail'); 
    
        function my_front_end_login_fail($username){
            // Get the reffering page, where did the post submission come from?
            $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')){
                // let's append some information (login=failed) to the URL for the theme to use
    
                  ////already not login failed append
                  if(!strstr($referrer,'&login=failed'))
                   {
                     wp_redirect($referrer . '&login=failed'); 
                   }
                  else
                   {
                   ////if alreday append go to same url
                     wp_redirect($referrer); 
                   }
    
            exit;
            }
    
        }