• Resolved danpecha

    (@danpecha)


    Hello,
    I have problem with redict users to page, after login(no registration), by role.
    Plugins for this redict are not working. Can you help me find solution.

    Thanks

Viewing 1 replies (of 1 total)
  • Plugin Support sanjuacharya77

    (@sanjuacharya77)

    Hi @danpecha,

    We are really sorry for the delayed response. Currently, we don’t have a direct setting to redirect after login based on the user role. But it can be done with the code snippet. Please add the given code on your active theme’s functions.php file.

    Here is the code:

    add_filter( 'user_registration_login_redirect', 'ur_redirect_back', 10, 2 );function ur_redirect_back( $redirect_url, $user ) {
        $current_user = (object) $user;
        $roles        = isset( $current_user->roles ) ? (array) $current_user->roles : array();
        if ( in_array( 'administrator', $roles, true ) ) {
            $redirect_url = 'https://my-site.com/administrators';
        } elseif ( in_array( 'customer', $roles, true ) ) {
            $redirect_url = 'https://my-site.com/customers';
        }
        return $redirect_url;
    }

    Note: Replace the redirect URL with your site link where you want to redirect.
    Do let me know whether it helps or not and I will get back to you.

    Thanks and Regards!

Viewing 1 replies (of 1 total)
  • The topic ‘Redict after login by role’ is closed to new replies.