• hi,
    I want to show logged in user/customer name in top bar of my website, i managed to get login/logout & register by plugin, but im not able to add user name or email ID of loged in user in my website

    so far i get this php code
    <?php global $user_login, $user_identity; get_currentuserinfo(); if ($user_login); ?> Welcome <?php echo $user_identity; ?> !
    but i dont know how to place where to place this code to

    can anyone help me with this?
    my website

Viewing 6 replies - 1 through 6 (of 6 total)
  • Nabil

    (@nabil_kadimi)

    This will give you a WP_User object

    $current_user = wp_get_current_user();

    Then you can get any info you need:

    echo 'Username:   ' . $current_user->user_login . '<br />';
        echo 'User email: ' . $current_user->user_email . '<br />';
        echo 'User first name:   ' . $current_user->user_firstname . '<br />';
        echo 'User last name:    ' . $current_user->user_lastname  . '<br />';
        echo 'User display name: ' . $current_user->display_name   . '<br />';
        echo 'User ID: ' . $current_user->ID . '<br />';

    Source: https://codex.www.ads-software.com/Function_Reference/wp_get_current_user#Default_Usage

    Thread Starter ltsharma

    (@ltsharma)

    thanks for replay,
    where i need to put this?
    i want to show username on top menu bar

    Nabil

    (@nabil_kadimi)

    Find the piece of code that is responsible for outputting the top menu bar (probably header.php), and add this code to it, use your PHP/HTML/CSS to get the desired output.

    Thread Starter ltsharma

    (@ltsharma)

    sorry, im not able to do what you said, its confusing me,

    let me clarify,
    This below is to show logged in username

    $current_user = wp_get_current_user();
    echo ‘User display name: ‘ . $current_user->display_name . ‘
    ‘;

    it it right?

    if yes, i need to add this on header.php file.
    i’m not pro in this,so how to add this to php file?
    or How to add this in CSS?

    i need to place this function to here in my site
    <div class=”col-md-6 col-sm-6 kad-topbar-left”>

    Thank you

    Hi Guys,

    I managed to do this with the code below. However, how do I get the displayed username to be a link to the user profile?

    <?php if (is_user_logged_in()){
    global $current_user; get_currentuserinfo();
    echo(‘Hi, ‘ . $current_user->user_login . ‘ ‘);

    }
    else {
    echo “Welcome, Visitor “;
    };
    ?>

    Thanks!

    Thread Starter ltsharma

    (@ltsharma)

    hey, sorry for late replay finally got

    <div class="top-login">
    <?php
    if ( is_user_logged_in() ) {
        echo 'Logged in as, ';
        global $current_user;
    if ( isset($current_user) ) {
     echo $current_user->>user_login;
    }
    } else {
        echo 'Guest';
    }
    ?>
    </div>

    add and style class top-login in style css, its done
    I managed to show first name of user but is there any way to show name with link to his account url link?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘loged in username in top bar of theme’ is closed to new replies.