in PHP

Display Gravatar From Email Address


In a previous article you learnt how you can display the the author avatar in Wordpress. But if you aren't using Wordpress then you will need to use a Gravatar.


A Gravatar is your image that follows you from to different sites and will appear as your image next to your name. So if you make a comment on a blog they will be able to use your Gravatar to display your personalised image. Gravatars helps people become familiar with your image. Your Gravatar is linked to your email address so if you use the same email addresses on different blogs you will have a different Gravatar.

Display Your Gravatar On Page

To display your Gravatar on the page use the following snippet.

   $email = ""
   $gravatar_link = '' . md5($email) . '?s=128';
   echo '<img src="' . $gravatar_link . '" />';

Display Wordpress Author Gravatar

Instead of using the Wordpress built in avatar you might want to use your Gravatar on all your posts. To do this you can modify the above snippet. Go to the single.php page and enter the following where you want to display your gravatar.

   $gravatar_link = '' . md5(get_the_author_email()) . '?s=128';
   echo '<img src="' . $gravatar_link . '" />';

Upgrade to access all content on Paulund

Members unlock all tutorials and snippets

Access to all downloadable content

Access to code examples before others

Sign Up Now

Already a member? Login here

Subscribe To The Weekly Newsletter

Get weekly updates to your email