You’ve probably seen a lot of posts around the web on how to add author avatars to your WordPress posts, well here’s another one!
In this new blog theme I’m going to release soon, based on my Compose WordPress theme, I wanted to add a nifty section below each post to show the authors avatar, name and their description.
So here’s what you need to get that done.
<?php echo get_avatar( get_the_author_meta('email'), '48', '', get_the_author_meta('nickname') ); ?>
Breaking it down:
get_avatar: This is the main function to call the avatar, now let’s customize it.
get_the_author_meta('email'): This will get the avatar tied to the email provided by the author.
48: The avatar size, can be changed in multiples of 2.
get_the_author_meta('nickname'): This part will assign an alternative value to the image, so that it’s accessible by screen readers and HTML compliant.
So there you have it! Now all you need is some CSS styling and you’re good to go!