Skip to content

Instantly share code, notes, and snippets.

@SErr0r
Created April 26, 2015 08:44
Show Gist options
  • Save SErr0r/ba5bcf8d1cd319e534db to your computer and use it in GitHub Desktop.
Save SErr0r/ba5bcf8d1cd319e534db to your computer and use it in GitHub Desktop.
Redirect WordPress Failed Logins to custom location
// hook failed login
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;
}
}
@SErr0r
Copy link
Author

SErr0r commented Apr 26, 2015

There’s just one problem with the above code; it will only redirect upon successful authentication! If your idea was to hide the default WordPress log-in screen, then sending users who fail at a log-in attempt back to the default log-in screen probably isn’t ideal. Here’s a hook and some code that you can put in your functions.php file that will redirect failed logins to any location of your choosing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment