WordPress.org

Ready to get started?Download WordPress

Forums

Problems Displaying Current User...? (10 posts)

  1. garethdaine
    Member
    Posted 8 years ago #

    Hi,

    I am new to using WordPress 2.0 as my WebLog software and was wondering does anyone know how to display the name of the currently logged in user?

    For example my username is 'Gareth' and on the sidebar on the right of my site I would like it to display that username their when I am logged in and also to do the same for the users of my site.

    This is my website http://www.truthmedia.co.uk

    Can you help? If so the help would be much appreciated. Thanks in advance.

    Regards

    Gareth

  2. moshu
    Member
    Posted 8 years ago #

    Don't crosspost and don't be impatient. 29 minutes waiting is nothing!
    When a knowledgable member will come around - they will answer your question.
    [I deleted your duplicate post]

  3. garethdaine
    Member
    Posted 8 years ago #

    Hi,

    I'm sorry for being impatient. My apologies. I didn't mean to offend. I will not cross post again.

    Regards

  4. moshu
    Member
    Posted 8 years ago #

    Good. Then you can go now and read this thread :)
    http://wordpress.org/support/topic/55135?replies=18

  5. garethdaine
    Member
    Posted 8 years ago #

    Hi,

    Thank you, I will. I am sorry I am very tired as it is 04:53 am here and I just wanted to get this done so I could get some sleep. Wrong course of action I know, so again apologies. Thank you for the help.

    Regards

  6. garethdaine
    Member
    Posted 8 years ago #

    Hi,

    Unfortunatly I don't know were I am supposed to implement this code?

    global $user_identity;
    get_currentuserdata();
    if ($user_identity) { echo "Hi $user_identity!"; }

    Any ideas?

    Regards

  7. moshu
    Member
    Posted 8 years ago #

    Where you want it to appear. You mentioned the sidebar. That would be the sidebar.php file in your theme.

  8. garethdaine
    Member
    Posted 8 years ago #

    I have implemented the code in the side bar but it returns an error.

    This code seems to work but does not shoe the username, probably because of the reason stated in the thread you gave me, i.e. $user_identity isn't defined outside of wp-admin.

    <?php printf(__('Hello, %s.'), $user_identity) ?>

    I receive the following error upon trying to implement this code in the side bar:-

    Code:-

    global $user_identity;
    get_currentuserdata();
    if ($user_identity) { echo "Hi $user_identity!"; }

    Error:-

    Fatal error: Call to undefined function: get_currentuserdata() in C:\Inetpub\vhosts\truthmedia.co.uk\httpdocs\wp-content\themes\blix\sidebar.php on line 56

    Regards

  9. garethdaine
    Member
    Posted 8 years ago #

    Hi,

    It's ok I have figured it out.

    All I did was combine and edit the two sets of code to produce this:-

    <?php global $user_identity;
    printf(__('Hello, %s.'), $user_identity) ?>

    It works like a charm now :D. Thank you for your help Moshu, much appreciated. Sorry again for the impatience.

    Regards

    Gareth

  10. moshu
    Member
    Posted 8 years ago #

    The other also should work if you change currentuserdata => currentuserinfo.
    I don't use any of them, just checked out now :)

Topic Closed

This topic has been closed to new replies.

About this Topic