Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im trying to display user login instead of user full name below each post avatar. Im using the following hook:

function my_member_username_link() {

    global $post;

    if (isset($post->post_author)) {

      $user_info = get_userdata($post->post_author);

      return '<a href="/' . $user_info->user_login . '/" title="' . $user_info->user_login . '">' . $user_info->user_login . '</a>';      




This works on each avatar close to each post, but acts weird in the right sidebar where my session is displayed.

Any help is welcome.

Thanks in advance.

share|improve this question

closed as off-topic by kaiser Aug 7 '14 at 11:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 1 down vote accepted

The reason it's not working in the sidebar is likely because the sidebar content is outside the Loop, and $post data, and thus, $post->post_author, are only available inside the Loop.

You could try setting a variable equal to $post->post_author while still inside the Loop, and then passing that variable to get_userdata() in your function call outside the Loop.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.