If you are using standard wordpress login form inside of your theme and you are battling with the redirect when a user enters the incorrect details then this code will help.
Normally the form has a “redirect_to” hidden field.. this however works only when the correct details are entered. When the incorrect details are entered it takes you to the normal login form. This snippet will help prevent that.
add_action( 'wp_login_failed', 'my_front_end_login_fail' ); function my_front_end_login_fail( $username ) { $referrer = $_SERVER['HTTP_REFERER']; if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) { wp_redirect( $referrer . '?login=failed' ); exit; } }