WordPress.org

Forums

[resolved] Display Greeting (3 posts)

  1. alpha1beta
    Member
    Posted 4 years ago #

    I'm trying to display a greeting on the homepage.
    Either Hello Guess, would you like to register or login?
    or If logged in, Hello $name

    I've been looking through codex, and tried, $current_user, wp_get_current_user and a few others, all of which do nothing.

    Now I know the problem (I think)
    I'm not including a file that contains these functions!

    Problem is, I can't figure out which one.

    I would Ideally like to display the username
    so if logged in
    Hello, USERNAME. (or other user)
    If not. Hello Guest.

    Could someone please point me in the right direction as far as picking which function will display the USERNAME best and what file its in, that i need to include to make it work. I'm using a custom theme, but its based off Twenty Ten and as for as the included files go, I haven't changed any inside header.php.

    (I have the if logged in code already)

  2. MichaelH
    Member
    Posted 4 years ago #

    Not exactly what you wanted but you can use the $userdata object

    <?php
    //if user logged in, warn if first name is not filled in
    if ( is_user_logged_in() ) {
      echo 'Welcome, registered user!';
      if ( $userdata->first_name ) {
        echo ' You have a first name of '. $userdata->first_name;
      } else {
        echo ' Please, visit your profile page and enter a First Name.';
      }
    } else {
    echo 'Welcome, visitor!';
    };
    ?>
  3. alpha1beta
    Member
    Posted 4 years ago #

    Thats not exactly what i was looking for, but i made me realize something that did work.

    <?php
    if ( is_user_logged_in() ) {
     global $current_user;
          get_currentuserinfo();
          echo 'Hello: ' . $current_user->display_name . "\n";
    } else {?> Hello Guest! <?php };
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.