Here’s another piece of php code for redirecting to any page after a login error in wordpress.
add_filter('login_redirect', '_catch_login_error', 10, 3);
function _catch_login_error($redir1, $redir2, $wperr_user)
{
if(!is_wp_error($wperr_user) || !$wperr_user->get_error_code()) return $redir1;
switch($wperr_user->get_error_code())
{
case 'incorrect_password':
case 'empty_password':
case 'invalid_username':
default:
wp_redirect('/login-failed'); // modify this as you wish
}
return $redir1;
}
My name is Amado Martinez. I'm a 23 year old programmer living in Reynosa, Mexico. I specialize in website systems. I'm not a frequent blogger, but I hope that you find my web development tips helpful and perhaps even AWESOME! Thanks for visiting :)
hi
thanks for ur code.It worked for me,it is able to redirect after failed login attempts , but the error message it is giving is not correct. It should show like incoreect password/username etc… but it shows error: not found..can u tell how to fix this?
hi sweta. for that you’d have to modify the code, for redirectioo to special page, for example if you want to show 3 different error pages. you would create a page for the ‘incorrect passowrd’ message, ‘empty password’ and ‘invalid username’, and then redirect accordingly:
switch($wperr_user->get_error_code()) { case 'incorrect_password': wp_redirect('/my-incorrect-password-page'); break; case 'empty_password': wp_redirect('/my-empty-password-page'); break; case 'invalid_username': wp_redirect('/my-invalid-username-page'); break; default: wp_redirect('/other-error-page'); }Hi, first of all thanks for the code, it works like a charm
I modified it a little so that user is sent to the same page after failed login attmpt. Is it possible to take care of situation when user left both login and password fields empty?