[Resolved] Redirect Logged In Users

Home Forums Support [Resolved] Redirect Logged In Users

Home Forums Support Redirect Logged In Users

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1298544
    Maria

    I’m trying to redirect logged-in users to a Members Only Home page when they log in. I tried the code below per David’s response on 2/7/20 #1157775 and changed ‘/logged-in-home’ to the page slug of the page I want to redirect them to but it doesn’t work. I’m currently using Peter’s Login Direct plugin but it’s causing me other issues and I’d like to get rid of that plugin. Am I missing anything from the code below?

    add_action( ‘wp’, function() {
    if ( is_front_page() && is_user_logged_in() ) {
    wp_redirect( home_url( ‘/logged-in-home’ ) );
    die();
    }
    } );

    #1298637
    Grant
    #1298677
    Maria

    Doesn’t help me. I have no idea what the $page = 2516 or update_option means. David’s code makes sense to me but seems like something is missing. Any other options?

    #1298931
    David
    Staff
    Customer Support

    Hi there,

    where and how are you adding the code?

    For reference this is the working code i just tested:

    add_action( 'wp', function() {
        if ( is_front_page() && is_user_logged_in() ) {
            wp_redirect( home_url( '/logged-in-home' ) );
            die();
        }
    } );
    #1299090
    Maria

    Where and how should I be adding the code?

    #1299207
    David
    Staff
    Customer Support

    It’s PHP – this document explains:

    https://docs.generatepress.com/article/adding-php/

    #1299436
    Maria

    I realize it’s PHP. I was hoping for a bit more explanation. I put the following snippet in the functions.php of my child theme.

    add_action( ‘wp’, function() {
    if ( is_front_page() && is_user_logged_in() ) {
    wp_redirect( home_url( ‘/members-home-page’ ) );
    die();
    }
    } );

    After logging in, I was directed to the Dashboard, not the Members Home Page I intended. I don’t know what I’m doing wrong.

    #1299774
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    How are you logging in?

    That code will redirect a logged-in user if they go to the front page. It won’t necessarily redirect them as soon as they log in.

    In order to redirect someone from the login form, you would need them to go to the login form using a specific link.

    If you search for “WordPress redirect after login”, you should find a lot of answers. This one looks promising: https://stackoverflow.com/a/8127629/2391422

    #1299858
    Maria

    Thanks, Tom for the explanation. I totally understand now. I wanted to redirect them as soon as they log in.

    #1300817
    Tom
    Lead Developer
    Lead Developer

    No problem! 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.