Created
April 26, 2015 08:44
-
-
Save SErr0r/ba5bcf8d1cd319e534db to your computer and use it in GitHub Desktop.
Redirect WordPress Failed Logins to custom location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.