• Resolved zvik

    (@zvik)


    Hi

    I am trying to redirect a specific user to a specific URL.

    For example:
    When ‘User 1’ logins goes to https://www.example.com/user-1
    When ‘User 2’ logins goes to https://www.example.com/user-2
    and so on…

    Shortcode I’m using for login page:
    [user_registration_my_account redirect_url=profile]

    I have tried to use Peters Login Redirect but this wont work with the User Registration Plugin only with the WordPress Default login. Is there an alternative way to achieve this?

    Thanks in advance!

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

    (@sanjuacharya77)

    Hi @zvik,

    We are really sorry for the delayed response. Currently, we don’t have a direct setting to redirect a specific user to a specific page after login. But you want to redirect user based on the user role then 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 ‘How do I Redirect a Specific User to a Specific URL’ is closed to new replies.