How To Enable Gravatar On Your Blog Without Plugin
If you're new here, you may want to subscribe to my RSS feed or via Email. Thanks for visiting!
Do you know WordPress 2.5 has a built-in Gravatar feature? Have you tried to enable it and still no picture of you appearing beside your name or your commentator’s name? Well, I ditched it altogether and instead I place a code into my comment section without even enabling it in the first place. And I use no plugin.
So how do you enable Gravatar on your blog without plugin?
It is easy but not necessarily simple! If you are not inclined to do ‘copy & paste’ and modify your comments.php template. I suggest you hire a MyBlogLog Avatars plugin to do the job. For the sake of this article, I merely share the method I used before the birth of WP 2.5.
Now let’s put your commentator’s face behind a name?
To begin with, edit [ Design > Theme Editor ] your comment.php (make sure that it is writable) and look for this line of code
<?php comment_author_link() ?>
Copy the code below and paste it anywhere within the comment loop you want the gravatar to appear; preferably just before the author’s link,
<span class="avatar">
<?php if(!empty($comment -> comment_author_email)) {$md5 = md5($comment -> comment_author_email);
$default = urlencode('DEFAULT PATH');
echo "<img src='http://www.gravatar.com/avatar.php?gravatar_id=$md5&size=40&default=$default' alt='' />";
}?>
</span>
You can style it by giving a class to the image with float:left on your CSS or even adding some border to it as well.
You can add the following CSS style to your stylesheet to float the gravatar to the left;
img.avatar {
float:left;
}
If you are not comfortable with image size, you can change the code &size=40 to any size you prefer. 40 just means it is 40×40 pixel in dimension. Got it?
Update: Please copy the default image on the left (avatar.gif) and upload it to your image directory.
Just don’t forget to change DEFAULT PATH to the url where the default image is saved. Otherwise, if the commentator has no Gravatar account, nothing will appear.
That’s it
If you are adopting another method that serves the same purpose, I’ll like to know how you do it. Oh, I love my Gravatar.
PS: As much as I’d like to thank the author from whom I learn the code, sadly to say, I couldn’t remember you. Anyway, thank you.
Did you miss any of these?
- Putting A Face Behind A Name With Gravatar
- Probably Not-So-Often-Used Way To Edit Your Comment
- A Beginner’s Guide to WordPress Plugins
- 50 Tips To Build Traffic For Your Blog
- I Want a WordPress Plugin to..
Readers who viewed this page, also viewed:
- N/A
19 Comments
Got something to say?
Your input matters. If you have any thoughts on ' How To Enable Gravatar On Your Blog Without Plugin', I'll be pleased to hear from you.







Hi,
Thank you for your comment on my WordPlay blog and for the compliment on the site design!
You have a nice blog here with a great cross-section of information. I zoomed the page about free WP installation; that’s a great offer that deserves some notice.
:-)
Hey, thank you for stopping by to this little site which has been my playground for the last couple of weeks. It’s nice to receive a compliment once in a while. It just makes it more worthwhile to do it better. I appreciate and value your comment.
With regard to the WP installation, I just thought I could help those who are still hesitant to do it themselves. Glad you notice it.
I’ve got the Gravatar thing down on the list of things to do. One day when I find 30 seconds to spare…
Grrr! that spam protection. I understand why it’s there, but I forget to check it every time!!!
Anyway, on my second attempt at a comment….
Thanks for diirecting me here Yan, much appreciated.
So I added that piece of code to my comments file - no problem.
And then I scrolled down and read this:
“Just don’t forget to change DEFAULT PATH to the url where the default image is (just like the one on the left). Otherwise, if the commentator has no Gravatar account, nothing will appear.”
Now I admit I’m dense when it comes to messing around with Wordpress php files and and I’m wondering exactly what you mean by ‘default path to the url’…
And also, I posted the code above, which had the image floated left… but the avatars are appearing on the right!
Help!!!
zania’s last blog post..Why I Refuse To Make My Blogs Dofollow
@zania - I’m not too sure if you copy and paste the exact code as the class “floatleft” may not exist on your CSS file. So you need to use
style="float:left;"instead.Now please copy the image (avatar.gif) you see on the post (or you could use any image of your choice) and upload it to your /images/ directory.
If you follow the above, your default url for no gravatar image should be something like
http://zaniadultonline.com/images/avatar.gif and you are good to go.
Hmmm…
That second edit didn’t work as well as planned.
It blacked out my single post page completely.
I had to delete the comments php file and upload it again.
Tried again, but it still didn’t work, and now I have no avatars again …
Has the code positioning changed by the way…?
zania’s last blog post..Why I Refuse To Make My Blogs Dofollow
I doubt so. I’m sorri perhaps my instruction wasn’t too clear to you. You are actually doing it right the first time, you just need to float it the right way.
If you are comfortable, you could send me your comment.php and I’ll take a look at it.
Thanks Yan,
file sent to you now.
on the second attempt anyhow.. :)
zania’s last blog post..Why I Refuse To Make My Blogs Dofollow
Just to let you (and anyone else reading this) know that everything works fine now and I have avatars in my comments, yay!
Thanks so much Yan for all your help.
Now I must go and read your latest post ;)
zania’s last blog post..Why I Refuse To Make My Blogs Dofollow
Hi Yan,
I’m trying to enable Gravatar on my blog but encountered some problems. I’ve just emailed you providing you some information. Hope you can help.
Thanks
Peter
@Peter - Hmmm, I guess I wasn’t very clear with my explanation on the post. I have rewritten and added some code into it to clear some doubts.
Hi Yan,
Just wanted to let you know I’ve got gravatar on my blog now. Hurray! Hey thanks a lot man. Very rarely do I go near my php files as I’m afraid to mess up things. I wouldn’t have done this without your help. It’s really good to see faces to their comments.
Peter Lee
Hey Yan,
My gravatar appears on my blog but not on yours. Any idea why? It’s showing black square on your blog. Do you see that too..
Peter
@Peter - Yes, I see it. What email address do you use to accompany your gravatar, may I ask?
Hi Yan,
I used Gmail…what could be the problem. It’s strange as it is showing up at my blog. But I had some problem setting my account and I did see this black patch there before I removed and re-do it. Perhaps you can try to clear your cache to see if it works.
Peter
@Yan -
@Peter - Did you attach the image to your email address after you upload it to your gravatar account? Uploading alone doesn’t work, you need to assign the uploaded image to the specified email.
Hi Yan,
I did attach the image to my email address. I just went over to PB’s blog and found my gravatar there as I posted a comment 3 days ago, so I guess my set-up is good. My only guess is that when I encountered the problem during the account set up which gave me that black square, your computer registered that as my image. That means image changes are not retrospectively changed in blog comments. It’s OK Yan, I’m only faceless in your blog ha! No big deal! Still very happy I got it done and thanks to you again.
Peter
@Work At Home Ideas - I can see you now, Peter. I guess my blog is kind of retarded in that sense but everything seems to be fine now. I’m glad I could be of help.
Trackbacks
How To Enable Gravatar On Your Blog Without Plugin…
Do you know WordPress 2.5 has a built-in Gravatar feature? Have you tried to enable it and still no picture of you appearing beside your name or your commentator’s name? Well, I ditched it altogether and instead I place a code into my comment section…