This topic has 23 replies, 9 voices, and was last updated 10 years by metalmick.

  • Author
  • #7052
     knuhkles
    Participant

    I love this theme more and more.. Its getting better and better. Is their a way to redirect to a certain page after login? i dont want to use another plugin if their is a way already.

    #7053
     adam
    Participant

    this will redirect users to their profile when they log-in and the administrator (you) to wp-admin:

    COPY CODE
    
    /* Filter the redirect url for login*/
    add_filter("login_redirect","kleo_redirect_to_profile",100,3);
     
    function kleo_redirect_to_profile($redirect_to_calculated,$redirect_url_specified,$user){
    /*if no redirect was specified,let us think ,user wants to be in wp-dashboard*/
        if(!is_super_admin($user->ID))
            return bp_core_get_user_domain($user->ID );
        else
            return $redirect_to_calculated; /*if site admin*/
    }
    

    it goes in the functions.php file of your child theme. is this what you’re looking for?

    #7056
     knuhkles
    Participant
    This reply has been set as private.
    #7151
     SQadmin
    Keymaster

    so instead of: return bp_core_get_user_domain($user->ID ); put return ‘/my_page_link’;

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #7172
     knuhkles
    Participant

    ok so the final code should be this…

    COPY CODE
    
    /* Filter the redirect url for login*/
    add_filter("login_redirect","kleo_redirect_to_profile",100,3);
     
    function kleo_redirect_to_profile($redirect_to_calculated,$redirect_url_specified,$user){
    /*if no redirect was specified,let us think ,user wants to be in wp-dashboard*/
        if(!is_super_admin($user->ID))
           return '/my_page_link';
        else
            return $redirect_to_calculated; /*if site admin*/
    }
    
    #7273
     SQadmin
    Keymaster

    Yes that is correct

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #7817
     hughm
    Participant

    I am using the above code to try and redirect first time log-ins to the change-avatar page. I tried the following code but it did not work. Am I making a syntax mistake?

    return ‘/USERNAME/profile/change-avatar/’;

    I used some code in my functions.php file to change the path of member profiles to get rid of “members” and display at the root of the url.

    #7841
     hughm
    Participant

    This is the code I use in my child theme functions.php to put profile names at the root. Perhaps this is conflicting with above code?

    // put profiles in the root
    define ( ‘BP_ENABLE_ROOT_PROFILES’, true );

    #7925
     SQadmin
    Keymaster

    Hi, You should look at @adam’s code: https://archived.seventhqueen.com/forums/topic/redirect-after-login-2#reply-7053
    and change from the root of the profile to the change avatar page by changing:
    return bp_core_get_user_domain($user->ID );
    with
    return bp_core_get_user_domain($user->ID ).’/profile/change-avatar/’;

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #7983
     hughm
    Participant

    I tried this code and played around with it but couldn’t make it work. I am trying to take first time log-ins to the change avatar page. This code takes new users to the login page on first login:

    /*if the user is not site admin,redirect to his/her profile*/
    if(!is_super_admin($user->ID))
    return bp_core_get_user_domain($user->ID ).’/profile/change-avatar/’;

    Any ideas?

    #7986
     knuhkles
    Participant

    Here guys… this is my snippet… it works

    add_action( ‘template_redirect’, ‘my_redirect_home’ );

    function my_redirect_home()
    {
    if( is_user_logged_in() && is_front_page() )
    {
    wp_redirect( site_url( ‘/logged-in’ ) );
    exit();
    }
    }

    #7990
     hughm
    Participant

    Sorry to say I couldn’t get it to work. The below gets me to the new user profile but can’t seem to get the next step to the change-avatar page.

    if(!is_super_admin($user->ID))
    return bp_core_get_user_domain($user->ID );

    #8063
     Abe
    Keymaster

    Hi, Like I said:
    You should look at @adam‘s code: https://archived.seventhqueen.com/forums/topic/redirect-after-login-2#reply-7053
    and change:
    return bp_core_get_user_domain($user->ID );
    with
    return bp_core_get_user_domain($user->ID ).’/profile/change-avatar/’;

    what you have pasted is just some part of the code

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    ---
    @ SeventhQueen we do our best to have super happy customers. Thanks for being our customer.

    #8073
     hughm
    Participant

    Hi thanks,
    Yeah, I did insert the piece of code into Adam’s and still couldn’t get it to work. Here is the entire code that I tried:

    /* Filter the redirect url for login*/
    add_filter(“login_redirect”,”kleo_redirect_to_profile”,100,3);

    function kleo_redirect_to_profile($redirect_to_calculated,$redirect_url_specified,$user){
    /*if no redirect was specified,let us think ,user wants to be in wp-dashboard*/
    if(!is_super_admin($user->ID))
    return bp_core_get_user_domain($user->ID ).’/profile/change-avatar/’;
    else
    return $redirect_to_calculated; /*if site admin*/

    This redirects back to the home page.

    #8131
     Abe
    Keymaster

    That looks good. You should have your child theme activated.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    ---
    @ SeventhQueen we do our best to have super happy customers. Thanks for being our customer.

    #8322
     road2love
    Participant

    Hey there, I’m having the same problem, activated the child theme and entered the code to child-theme functions.php like it shows in Adams post..but couldn’t get it to work. When my users login they’re not redirected to their profile page but back to the homepage and it looks like they have to login again. Then when clicking on any other page the profile button top right appears.

    Do you mind me asking knuhkles where exactly put your snippet of code?

    #8401
     Abe
    Keymaster

    Hi, That code works, just added it to sweetdate-child/functions.php. Is the same code as here: https://archived.seventhqueen.com/forums/topic/redirect-user-to-their-profile-after-login

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    ---
    @ SeventhQueen we do our best to have super happy customers. Thanks for being our customer.

    #8445
     hughm
    Participant

    I noticed that @road2love was having trouble getting this to work. I never was able to make this code redirect to the change-avatar page. The code above failed and redirects to the home page. I ended up settling on just redirecting to the profile page, but if someone figures out how to get it to work please let me know.

    #8575
     ACTasarim
    Participant

    @ adam ‘s code didn’t work for me either…

    #8631
     Abe
    Keymaster

    The code base is in this topic:
    https://archived.seventhqueen.com/forums/topic/redirect-user-to-their-profile-after-login

    modified it should look like:

    COPY CODE
    
    //custom redirect
    add_filter("login_redirect","kleo_redirect_to_profile",100,3);
     
    function kleo_redirect_to_profile($redirect_to_calculated,$redirect_url_specified,$user){
    /*if no redirect was specified,let us think ,user wants to be in wp-dashboard*/
        if(!is_super_admin($user->ID))
            return bp_core_get_user_domain($user->ID ).'/profile/change-avatar/#item-nav';
        else
            return $redirect_to_calculated; /*if site admin*/
    }
    

    You must be a regular user, not an admin

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    ---
    @ SeventhQueen we do our best to have super happy customers. Thanks for being our customer.

    #11420
     sermsak
    Participant

    i already add the code from https://archived.seventhqueen.com/forums/topic/redirect-user-to-their-profile-after-login . and i test to register. the page said – User registration is currently not allowed.
    Please comment . Thank you

    #11422
     sermsak
    Participant

    Hello. Support Team

    Now i can fix this problem by wordpress help. Sorry to loose your time.
    Thanks

    #11572
     Abe
    Keymaster

    Hi, enable registration from Settings – General

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    ---
    @ SeventhQueen we do our best to have super happy customers. Thanks for being our customer.

    #14552
     metalmick
    Participant
Viewing 24 posts - 1 through 24 (of 24 total)

The topic ‘Redirect After Login’ is closed to new replies.

Log in with your credentials

Forgot your details?