Login redirect to previous page
I have a custom login page at http://netballscoop.com/log-in/
When you fill the username and password it redirects you to the previous page you were on perfectly. When you click Log Out it redirects you to the same page. So this all works well.
If you leave the username/password blank or have an error it will lead you to wp-login. To prevent this I have used the code from https://stackoverflow.com/questions/11477107/redirect-away-from-login-page
add_action('login_redirect', 'redirect_login', 10, 3);
function redirect_login($redirect_to, $url, $user) {
if($user->errors['empty_password']){
wp_redirect(get_bloginfo('url').'/log-in-error/');
}
else if($user->errors['empty_username']){
wp_redirect(get_bloginfo('url').'/log-in-error/');
}
else if($user->errors['invalid_username']){
wp_redirect(get_bloginfo('url').'/log-in-error/');
}
else if($user->errors['incorrect_password']){
wp_redirect(get_bloginfo('url').'/log-in-error/');
}
else{
wp_redirect(get_bloginfo('url').'/log-in');
}
exit;
}
This works great for log in errors on my website. But now the login redirect takes you to http://netballscoop.com/members/testing (The user ‘Testing’ is taken tor their BuddyPress member’s profile page).
How do I redirect the user to the previous page when they log in?
Leave an answer