WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display name of logged user (5 posts)

  1. pfernandezm59
    Member
    Posted 4 years ago #

    Please, how to display in my header the name of the logged user in my header? (eg.: My name is webmaster, and I'd like to see Webmaster in the header of my index page)
    Thank you very much

  2. cubecolour
    ɹoʇɐɹǝpoɯ
    Posted 4 years ago #

    Put this in your header.php were you want it to appear

    <?php global $current_user;
          get_currentuserinfo();
          echo 'You are logged in as: ' . $current_user->user_login;
    ?>
  3. pfernandezm59
    Member
    Posted 4 years ago #

    It works fine, but one comment. Is it possible that the phrase: 'You are logged in as: ' would appear only if the users are logged in?
    Maybe an If.. loop?
    Thanks

  4. cubecolour
    ɹoʇɐɹǝpoɯ
    Posted 4 years ago #

    Yes the code I put in the post above is appropriate for a private blog
    You could flesh it out like this for a public-facing one:

    <?php
    if ( is_user_logged_in() ) {
        global $current_user;
          get_currentuserinfo();
          echo 'You are logged in as: ' . $current_user->user_login;
    } else {
        echo 'you are not logged on';
    };
    ?>
  5. pfernandezm59
    Member
    Posted 4 years ago #

    Working Fine!!!
    thank you very much numeeja!!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.