waynedunkley
3/25/2015 - 12:37 AM

If using a custom login form with wp_login_form(); the default action with an incorrect login is to forward the user to the default wp-admin

If using a custom login form with wp_login_form(); the default action with an incorrect login is to forward the user to the default wp-admin login screen as this is the same action as the default login form. Add the following to functions.php to redirect them back to the same page but with a login=failed url parameter

function fp_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') ) {
			$referrer = substr($referrer, 0, strpos($referrer, '?'));
		wp_redirect( $referrer . '?login=failed' );  // let's append some information (login=failed) to the URL for the theme to use
		exit;
	}
}
add_action( 'wp_login_failed', 'fp_login_fail' );  // hook failed login