Hey @christ59620
You can use the following piece of code, It will redirect the admin user to the backend and all other user roles to the home page of the site.
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*/
function login_cust_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator', $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} else {
return home_url();
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'login_cust_login_redirect', 10, 3 );
If this doesn’t work for you, there might be some plugin or theme conflict which is also applying the redirection.
Do let us know if this works for you.
Have a nice day!