1

I have got this form for login from the front-end.

   <form action="<?php echo site_url('wp-login.php', 'login_post'); ?>" method="post" <?php /*id="login-page-form"*/ ?>>

                            <label for="log"><?php _e('Usuario', 'gp_lang'); ?></label>
                            <input type="text" name="log" id="log" value="<?php echo esc_html(stripslashes($user_login), 1) ?>" size="22" placeholder="<?php _e('Usuario', 'gp_lang'); ?>" />

                            <label for="pwd"><?php _e('Contraseña', 'gp_lang'); ?></label>
                            <input type="password" name="pwd" id="pwd" size="22" placeholder="<?php _e('Contraseña', 'gp_lang'); ?>" />

                            <input type="submit" name="submit" value="<?php _e('Login', 'gp_lang'); ?> &rarr;" class="button" />
                            <label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> <?php _e('Recuerdame', 'gp_lang'); ?></label>
                            <input type="hidden" name="redirect_to" value="<?php if(preg_match("/key=/", $referrer)) { echo home_url(); } else { echo $referrer; } ?>"/>

</form>

Everything works fine except when the user uses wrong login details. If an user enters a wrong username or password the next page is "wp-login.php". But I want it to redirect to my homepage (get_site_url) with proper message to the user about the wrong login.

1

You can create a login failed action hook,

// hook failed login
add_action('wp_login_failed', 'my_front_end_login_fail'); 

function my_front_end_login_fail($username){
   wp_redirect(site_url(). '?login=failed'); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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