• Resolved alpha1beta

    (@alpha1beta)


    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)

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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!';
    };
    ?>

    Thread Starter alpha1beta

    (@alpha1beta)

    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 };
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display Greeting’ is closed to new replies.