[Resolved] How to Have different HOME URL for logged-in users

Home Forums Support How to Have different HOME URL for logged-in users

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1157129
    Martin

    Hi,
    I would like to be able to specify a different HOME URL for when a user is logged in. This would be very useful for my Members Website, where I need to top LOGO IMAGE URL to point to a PREVIEW page when users are logged out (website home url) and a MEMBERS URL (for logged in users).

    Is there a CSS I can use? Or any other simple trick?

    Thank you!

    Martin

    #1157170
    Leo
    Staff
    Customer Support

    Hi there,

    CSS can only change the visual side of things so cannot be used to change the URL.

    The theme itself doesn’t control the URL/permalink structure as well.

    I would recommend checking with the membership plugin support to see they can point you in the right direction.

    #1157725
    Martin

    Thank you for the reply.
    Perhaps you would know of a way to achieve this via the function.php file that I could add in a child theme of generatepress?

    #1157775
    David
    Staff
    Customer Support

    Hi there,

    Add this PHP snippet to your site:

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

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

    change logged-in-home to the page slug you want to redirect to.

    #1157805
    Martin

    Finally I found a way to do it. I’m sharing it here in case someone in the future would like to do something similar.

    1) Create a CHILD THEME from the used theme
    2) In the Child Theme Folder:

    A) Edit functions.php, and add this code:

    // shortcode to display content for loggedout and loggedin users : shortcodes are [loggedout] [loggedin]
    add_shortcode( ‘loggedout’, ‘visitor_check_shortcode’ );
    function visitor_check_shortcode( $atts, $content = null ) {
    if ( ( !is_user_logged_in() && !is_null( $content ) ) || is_feed() )
    return do_shortcode($content);
    return ”;
    }
    add_shortcode( ‘loggedin’, ‘member_check_shortcode’ );
    function member_check_shortcode( $atts, $content = null ) {
    if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
    return do_shortcode($content);
    return ”;
    }

    B) Copy the file header.php from your theme to the child theme.
    Then edit header.php:
    Add the following in the top of the header.php file, somewhere before <body>:

    <!– CUSTOM HOME URL ON GP LOGO IMAGE IF USER IS LOGGED-IN –>
    <?php
    if ( is_user_logged_in() ) {
    add_filter( ‘generate_logo_href’,’generate_add_custom_logo_href’ );
    function generate_add_custom_logo_href()
    {
    return ‘https://www.yourwebsite.com/logged-in-url&#8217;;
    } else {
    }
    ?>
    <!– END CUSTOM HOME URL IF USER IS LOGGED-IN –>

    #1157844
    David
    Staff
    Customer Support

    Glad you found a solution and thanks for sharing

    #1158150
    Martin

    Here’s a different approach I found, editing only the functions.php file in the child theme folder, which is preferred so the modification wont interfere with future updates of the main theme files:

    Add this code to the functions.php file:

    // LOGGED-IN USERS : HOME URL FOR TOP LOGO/HEADER IMAGE IN GENERATE PRESS
    if ( is_user_logged_in() ) {
    // set header logo image url when logged-in
    add_filter( ‘generate_logo_href’,’generate_add_custom_logo_href’ );
    function generate_add_custom_logo_href()
    {
    return ‘https://www.yourwebsite.com/logged-in-url/&#8217;;
    }
    }

    #1158152
    Martin

    I’ll mark this topic as resolved.

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