Support » Plugin: Ultimate Member – User Profile, User Registration, Login & Membership Plugin » How can I use shortcodes to greet Welcome username on Theme header

  • Resolved skandibanda

    (@skandibanda)


    Hi,
    I wanted to use somehow like below in my Header.php file to greet if they are logged in and for loggedout users say Hi Guest!

    [um_loggedin] Welcome, {first_name}[/um_loggedin]
    [um_loggedout] Welcome Guest! [/um_loggedout]

    But none of this short codes seems working. Can you please suggest how to achieve this. For time being, using a very generalized code below:

    `<div class=”top-header h2″> <!– Modified, for readability –>
    <h1>Samaikya Telugu Vedika</h1>
    <h2>తెలుగు సాంస్కృతిక సంఘం, స్టుట్గార్ట్ ప్రాంతం</h2>
    <?php
    /*if ( is_user_logged_in() ) {
    echo ‘Welcome, registered user!’;
    } else {
    echo ‘Welcome, visitor!’;
    }*/
    echo ‘<div class=”top-header h2″>’;
    if ( is_user_logged_in() ) {

    echo ‘<h2>Welcome, registered user!</h2>’;
    //echo $_SESSION[‘username’];
    //[um_loggedin] Welcome back {first_name} [/um_loggedin]
    } else {
    echo ‘<h2>Welcome Guest!</h2>’;
    }
    echo ‘</div>’;
    ?>
    </div>`

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @skandibanda

    You can try adding the following code to your theme/child-theme’s functions.php file or use the Code Snippet plugin to run the code:

    add_shortcode("um_display_username","um_101521_display_username");
    function um_101521_display_username(){
        $user_id = get_current_user_id();
        um_fetch_user( $user_id );
    
        return um_user("first_name");
    }

    Once the code is added to your site, you can use this shortcode to display the first name: [um_display_username]

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hey there!

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. 🙂

    Regards,

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