[Resolved] Show different Homepage Content Logged-In User

Home Forums Support [Resolved] Show different Homepage Content Logged-In User

Home Forums Support Show different Homepage Content Logged-In User

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1427809
    John

    Hi!

    I’m looking for a way to show different home-page/front-page content for a logged-in user/member. Ideas?

    Thanks!

    John

    #1427835
    John

    I tried this in snippets but it didn’t work for me.

    if( is_user_logged_in() ) {
        $page = get_page_by_title( 'page-title');
        update_option( 'page_on_front', $page->ID );
        update_option( 'show_on_front', 'page' );
    }
    else {
        $page = get_page_by_title( 'page-title' );
        update_option( 'page_on_front', $page->ID );
        update_option( 'show_on_front', 'page' );
    }

    Found this as a suggestion on Stackoverflow

    #1427986
    David
    Staff
    Customer Support

    Hi there,

    this topic may help:

    https://generatepress.com/forums/topic/redirect-logged-in-users/#post-1298931

    If you read further down Tom also provides a Stack Overflow for redirection upon login.

    #1428073
    John

    Thanks, David.

    I’m ok with redirecting users after login, what I’m trying to do is this;

      If a user is logged out and goes to the home page url, they see page A.
      If a user is logged in and goes to the home page url, they see page B.

    I tried using the following code mentioned by someone else in the thread you referenced (found here, with different page id’s) but when activated it changes the static and post pages in DASHBOARD > SETTINGS > READING to the same page. That fouls things up pretty good.

    ?php
    
    function switch_homepage() {
        if ( is_user_logged_in() ) {
            $page = 2516; // for logged in users
            update_option( 'page_on_front', $page );
            update_option( 'show_on_front', 'page' );
        } else {
            $page = 2; // for logged out users
            update_option( 'page_on_front', $page );
            update_option( 'show_on_front', 'page' );
        }
    }
    add_action( 'init', 'switch_homepage' );
    
    ?>
    #1428110
    Leo
    Staff
    Customer Support

    I would recommend starting a topic on WordPress Stack if the link David provided doesn’t solve the issue:
    https://wordpress.stackexchange.com/

    This isn’t a GP related question so we can only provide limited help here.

    Thanks for your understanding ๐Ÿ™‚

    #1428117
    John

    Will do. Thanks, Leo.

    #1428120
    Leo
    Staff
    Customer Support

    No problem ๐Ÿ™‚

    #1428185
    John

    On the off chance that someone else has this same question, here is a link on StackExchange that addresses this issue.

    #1428213
    Leo
    Staff
    Customer Support

    Awesome.

    Thanks for sharing!

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