Skip to content

Instantly share code, notes, and snippets.

@wplit
Created July 26, 2021 01:59
Show Gist options
  • Save wplit/1da9f7a1a497459f6d5b55ff4d7f2661 to your computer and use it in GitHub Desktop.
Save wplit/1da9f7a1a497459f6d5b55ff4d7f2661 to your computer and use it in GitHub Desktop.
Prevent redirect if WP login form failed
// Prevent redirect if login form failed
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment