[ad_1]
Hi @nicolauria,
The code you are trying to use is not working as intended because the login_redirect filter is applied before the global user object is loaded so the checks used for checking the user role are not yet available.
The way to get around that is to add the logic inside the snippet and disable the conditional logic.
Here’s an updated snippet that should achieve what you are looking for:
function subscriber_login_redirect( $redirect_to, $requested_redirect_to, $user ) {
if ( $user instanceof WP_User && user_can( $user, 'subscriber' ) ) {
$redirect_to = home_url();
}
return $redirect_to;
}
add_filter('login_redirect', 'subscriber_login_redirect', 10, 3);
