0

Can anyone tell How to check User Role and redirect to specific page according to Role when login in Wordpress?

Thanks.

2 Answers 2

1

you can do this redirection with this filter :

add_filter("login_redirect", function ($redirect_to, $requested_redirect_to, $user) {


    if (    is_a($user, "WP_User")
        &&  user_can($user, "role_to_test")
    ) {

        $redirect_to = home_url("/page_slug/");

    }


    return $redirect_to;

}, 10, 3);
0
1

Check role and redirect to specific page by slug or ID

Check single role.

if( current_user_can('editor') ) { 

    $page = get_page_by_title('thank-you');

    wp_redirect(get_permalink($page->ID));

} 

Check role for multi.

if( current_user_can('editor') || current_user_can('administrator') ) {  

    $page = get_page_by_title('thank-you');

    wp_redirect(get_permalink($page->ID));

} 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.