Take the 2-minute tour ×
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>';      

    } 


}

add_filter('bp_core_get_userlink','my_member_username_link');

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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