How do I get the authors avatar? Buddypress plugin or any plugin.

I have found this inside my PHP code:

"<i class="fa fa-user"></i><span>'.get_the_author().'</span></div>';"

It shows a small image before the author's name, I wanted to change the fa fa-user into author's avatar or buddypress avatar.

What will be the script to do that?

  • if you want to make the icon inside author's avatar. you need a css to do it.
    – ucon89
    Commented Jul 3, 2015 at 8:49

2 Answers 2


The function you're looking for is get_avatar - you should put in something like this:

<?php echo get_avatar( get_the_author_meta( 'ID' )); ?>
  • Hi there is an error it doesn't work. I substitute the code with the code you gave me, it shows error.
    – user74285
    Commented Jul 3, 2015 at 8:28
  • The function should output an img element. How did you use it exactly?
    – lucian
    Commented Jul 3, 2015 at 8:55
  • instead how do you put the buddypress avatar inside the div or i-tag?
    – user74285
    Commented Jul 3, 2015 at 9:38
  • I dont know if the buddypress avatar is fetched with the same function, I suppose it should. Did you try it like this? <i><?php echo get_avatar( get_the_author_meta( 'ID' )); ?></i>
    – lucian
    Commented Jul 3, 2015 at 10:41
  • still error let me paste the whole code: $output .= '<div class="pl-detailcnt">'; if($this->pw_grid_author=='no') { $output.=' <div class="pl-postmeta" > <i class="fa fa-user"></i><span>'.get_the_author().'</span></div>'; }
    – user74285
    Commented Jul 3, 2015 at 11:04

There are two methods to get user avatar in WordPress.

1st Method:

if (get_the_author_meta('email')) {
  echo get_avatar(get_the_author_meta('email'), '60');

2nd Method:

<?php echo get_avatar(get_the_author_meta('ID')); ?>

3rd Method

  <source srcset="<?php print get_avatar_url(get_current_user_id(), ['size' => '51']); ?>" media="(min-width: 992px)" />
  <img src="<?php print get_avatar_url(get_current_user_id(), ['size' => '40']); ?>" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.