Support

Account

Home Forums Backend Issues (wp-admin) Redirect after login to specific page driven by user field

Unread

Redirect after login to specific page driven by user field

    • Gipac

    • November 26, 2019 at 9:43 am

    Hi all,

    I can easely retrieve user name, by user field type

    $userID = (int)get_field('utente');
    $theuser = get_userdata($userID); 
    echo 'name: ' . $theuser->user_login;

    My goal is to use this function to redirect a non admin user to a specific page after the login, where the url is mysite.com/username

    putting this function in function.php should be

    function my_login_redirect() {
    $userID = (int)get_field('utente');
    $theuser = get_userdata($userID); 
        if ( isset( $user->roles ) && is_array( $user->roles ) ) {
            if ( in_array( 'administrator', $user->roles ) ) {
                return $redirect_to;
            } else {
                return home_url($theuser->user_login);
            }
        } else {
            return $redirect_to;
        }
    }
    
    add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );

    but after login the user is redirectet to profile page…
    Any ideas?
    Thanks a lot!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.