BuddyDev

Search

[Resolved] Return to previous page after login

Tagged: ,

  • Keymaster
    (BuddyDev Team)
    Posts: 24080
    Brajesh Singh on #22811

    Hi Fabianski ,
    Welcome to BuddyDev.

    Are you using some plugin to redirect from the site pages to login? If yes, you can simply disable the Redirect to profile plugin and default WordPress login will redirect. Please make sure you set ?redirect_to to the current page while redirecting to login.

    
    wp_get_referer()
    

    Is not reliable and it will not work in most cases.

  • Member
    deleted on #22825

    thank you for your support!
    Actually I had not realized that who was redirecting was woocommerce, so I used this function that I found to redirect using a woo hook itself.
    It worked very well!

    function wc_custom_user_redirect( $redirect, $user ) {
    $role = $user->roles[0];
    $dashboard = admin_url();
    if( $role == 'administrator' ) {
        //Redirect administrators to the dashboard
        $redirect = $dashboard;
    } else {
        //Redirect any other role to the previous visited page or, if not available, to the home
        $redirect = wp_get_referer() ? wp_get_referer() : home_url();
    }
    return $redirect;
    }

    THANKSSSS!!!!!!

  • Keymaster
    (BuddyDev Team)
    Posts: 24080
    Brajesh Singh on #22828

    That’s good to know.

    Best regards
    Brajesh

The topic ‘ [Resolved] Return to previous page after login’ is closed to new replies.

This topic is: resolved