Redirect After Login Based On User Role
-
Hello Team,
I want to redirect users after login based on their user role. For example if user role is premium than it should redirect to /watch page or it should redirect to home page. I am using TuturLMS plugin with Kadence theme and this is my code snippet to redirect:
function custom_login_redirect() {
$user = wp_get_current_user();
// Check if the user is logged in and not an error
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
if ( in_array( 'premium', $user->roles ) ) {
return home_url( '/watch' );
} else {
return home_url( '/' );
}
}
}
add_filter( 'login_redirect', 'custom_login_redirect', 10, 3 );However this code snippet does not work, please give me solution. I have also tried LoginWP
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.