How to show an author's avatar within WordPress
If you'd like to show the author's avatar within a WordPress post, we'll show you how in this article. While the functionality is not built into WordPress (version 3.2.1 as of this writing), you can surprisingly accomplish this task with just one line of code.
In this article we'll update the top part of the post that says "Posted on" so that it shows the authors avatar. Refer to the screenshots below to see the results.
Showing an Author's Avatar in WordPress
- Log into your WordPress Dashboard
- In the left menu, under "Appearance", click "Editor"
- On the "Editor" page, find and click "content.php" in the list of files on the right of the page
Find this section of code:
<div class="entry-meta"> <?php twentyeleven_posted_on(); ?> </div><!-- .entry-meta -->
... and replace it with this:
<div class="entry-meta"> <? echo get_avatar( get_the_author_meta('user_email'), $size = '50'); ?> <?php twentyeleven_posted_on(); ?> </div><!-- .entry-meta -->
That's it, you're done! In this tutorial we placed the author's avatar at the top of the post (for the homepage). If you'd like show the author's avatar from anywhere else within the post (or on other pages), simply use the following code:
<? echo get_avatar( get_the_author_meta('user_email'), $size = '50'); ?>
Congratulations, now you know how to show an author's avatar within WordPress!
Support Center Login
Social Media Login
2015-03-09 3:50 pm
What happens when there is an update to WordPress. THe user will have to manually re-insert the changes again.
2015-03-10 10:24 am
I would think so. Any time a core file is modified it should be expected that it will need to be redone after an update.
2015-10-19 10:23 am
To avoid having to do this you need to set up a child theme.
2015-11-17 10:11 pm
You wouldn't necessarily have to make a child theme or re-do the changes in the theme. You could set up a plugin that filters the_title or the_content and returns the avatar with it.
2015-11-18 10:14 am
Thanks for your comment! We probably need to update this article as the handling of Avatars has definitely changed in WordPress with the latest versions. Thanks for your input!
If you have any further questions, please let us know.
2016-05-31 2:21 am
Great Great Great. i was looking for this fro last 12 hours with lot of google search and headache but didt found solutions, and your post worked like a magic for me
Bundle of thanks again dude :)