Dear all,
I want to redirect Subscribers and WordPress Admin to another url.
I have tried to do it with the following code but it does not work for me and I would like to improve it, or someone suggests a better coding.
I appreciate your efforts.
function custom_login_redirect($redirect_to, $request, $user) {
global $user;
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
if ( in_array( 'subscriber', $user->roles ) ) {
return home_url("https://destodo.com/mi-escritorio/");
}
}
return $redirect_to;
}
add_filter( 'login_redirect', 'custom_login_redirect', 10, 3 );
3
Answers
I think I have achieved it with the following modification to the codes that you sent, where the subscriber accesses a page and the administrator to the desktop.
This should do the trick. We filters the login redirect URL and redirect any users (including admin) to your redirect url.
You can try this:
It is working to redirect Subscribers and WordPress Admin to another URL