admin管理员组

文章数量:1290938

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?

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?

Share Improve this question edited Jul 2, 2015 at 22:10 gmazzap 46.3k6 gold badges95 silver badges147 bronze badges asked Jul 2, 2015 at 21:54 user74285user74285 1
  • 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
Add a comment  | 

2 Answers 2

Reset to default 7

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' )); ?>

There are two methods to get user avatar in WordPress.

1st Method:

<?php
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

<picture>
  <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']); ?>" />
</picture>

本文标签: How to get authors avatar