Displaying Avatar of the Post Author

Displaying the Avatar of the post author in WordPress based sites are nothing new. You might have already seen such avatar of the various post author in many different website. Today in this post, I will show you how to display your avatar on your blog post.

By default, WordPress has a built in function (get_avatar) which can easily display author’s avatar based on author’s ID or email address. Take a look at the following snippet which you can use within the loop of your theme’s single.php, index.php or archive.php page.

<?php echo get_avatar(get_the_author_email(), '60'); ?>

Over here, we grabbed the author’s email address (from author’s profile) and checked against the email address to fetch the avatar. The numerical value (60) represents the size of the avatar. Yes, You can play around with the size of the avatar.

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

Above snippet would display the author’s avatar as well but it would check the avatar associated with the user ID instead of email. All you need to do now is to place the snippet code within a div element and design or place it wherever you like using CSS.

However, it is important to note that this function won’t work if you don’t check the “Show Avatars” box from Setting > Discussion page. If you want to use your actual image as an avatar, I would personally recommend to use Gravatar. It’s easy and works on all WordPress based site. Gravatar could be really useful if you want to fetch the avatar using email address. Don’t forget to use the same email address (that you used on WordPress site) while registering at the Gravatar.

Source: WordPress Codex.

Today In History

  •  
  •  

Comment

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from Postable, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.