Add Gravatars to your wordpress theme

Add Gravatars to your wordpress theme

1 Star2 Stars3 Stars4 Stars5 Stars
Posted on March 9, 2009

A few days ago I was looking around the internet for a solution on how to add Gravatar avatars to my WordPress comments section, and I found out that its easier than I originally thought! I thought there might be quite a bit of code to implement but found out that it requires just one line of PHP. So here are the steps to adding user Gravatars to your comments.

Step One

The first thing to do i log into your blog and under ‘Settings’ click ‘Discussion’ scroll down to ‘Avatars’ and make sure that you have avatars turned on as shown below.

avatars1

Once the you have chosen your setup as above you are ready to add the code into your comments template.

Step Two

Now under ‘Appearance’ select ‘Editor.’ In the right hand column you should see all the files that refer to your current theme. Select ‘Comments comments.php’ the template code for the comments section of your blog will now load in the main window where you can make changes and edit the code.

Dependent upon how your theme is structured you should be able to roughly work out where the comments are pulled in as in the image below. I have highlighted where i have added the line of code to pull in users avatars, each comment is placed in a list item. The Gravatar code is then added straight after the opening list item tag.

Add this single line of code.

<?php if(function_exists('get_avatar')) { echo get_avatar($comment, '40'); } ?>

avatars2

And that’s it! Want to see a demo? then leave a comment below and you’ll see the avatars. You will need to style the position of the avatars, size etc which is controlled by the class .avatar

More tutorials from Papermashup
Comments
2 discussions around Add Gravatars to your wordpress theme
  1. Shameera Prajapriya says:

    Want to see a Demo. I think this should be good one. Thanks

  2. Karny says:

    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Looking for a registry cleaner to speed up your PC and show a full diagnostics?
Faster surfing with Dish Network High Speed Internet

Never miss an update from Papermashup

Get notified about the latest tutorials and downloads.

Subscribe by Email

Get alerts directly into your inbox after each post and stay updated.
Subscribe
OR

Subscribe by RSS

Add our RSS to your feedreader to get regular updates from us.
Subscribe

Get in contact

Please use the form below to get in touch.

About Me

I'm Ashley Ford, Co-founder and Technical Director at Harkable.com London, UK. Previously I worked at InMobi, Spotify and MySpace. My interests include photography and making short videos I'm also an avid F1 fan. I'm always working on side projects. Here are a few: Easy Poll, We Deliver.



What do you specialise in?

I spend a lot of time coding in PHP and MySQL, as well as front end XHTML and CSS. I also specialise in javascript and the jQuery framework as well as being an avid designer. You can find me on dribbble

Interested in advertising?

If you'd like to advertise on Papermashup.com you can find details here Or use the contact link below for further advertising opportunities.

How do I contact you

You can contact me here. and I'm available for consultation, freelance, programming book reviews.

Get on the mailing list

Join over 3000 people who have subscribed to the Papermashup inbox message, and be the first to find out about tutorial, competitions and giveaways.