I currently use this plugin (https://buddydev.com/bp-redirect-to-profile-plugin-redirect-users-to-their-profile-on-login-on-buddypress-sites/) to redirect the user after login
It works great but I wanted it to redirect to the previous page it was before logging in.Example: he was on the forum, logged in and is redirected back to the forum.
Is this possible?
I tried to modify this part of the code
return bp_core_get_user_domain( $user->ID );
to this
return wp_get_referer();
but not work
thanks!
Hi Fabianski ,
Welcome to BuddyDev.Are you using some plugin to redirect from the site pages to login? If yes, you can simply disable the Redirect to profile plugin and default WordPress login will redirect. Please make sure you set ?redirect_to to the current page while redirecting to login.
wp_get_referer()
Is not reliable and it will not work in most cases.
thank you for your support!
Actually I had not realized that who was redirecting was woocommerce, so I used this function that I found to redirect using a woo hook itself.
It worked very well!function wc_custom_user_redirect( $redirect, $user ) { $role = $user->roles[0]; $dashboard = admin_url(); if( $role == 'administrator' ) { //Redirect administrators to the dashboard $redirect = $dashboard; } else { //Redirect any other role to the previous visited page or, if not available, to the home $redirect = wp_get_referer() ? wp_get_referer() : home_url(); } return $redirect; }
THANKSSSS!!!!!!
The topic ‘ [Resolved] Return to previous page after login’ is closed to new replies.