Hey @christ59620
May i know which do are you referring here?
Do know, You have to copy and paste the code in the functions.php file of your child theme.
If you need any assistance do let us know.
Have a nice day!
Good morning,
Thank you for your help.
I was referring to this code addition.
https://developer.ww.wp.xz.cn/reference/hooks/login_redirect/
Not being a child code of the theme, I will refer the addition to each modification of the theme (newspaper).
Thanks again.
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!