Fixing Gravatars for WordPress

Ok, I did some coding mumbo jumbo, and got the gravatars to work even for people who didn’t use lowercase emails. If you want to geek out on it, this is how I got it to work.

The gravatar function creates an md5 hash of your email address, and tags it onto the end of the URL when it goes to get your icon from the gravatar server. That’s how it knows which icon to return. By using a hash encryption, your email address doesn’t show up in the html for the page. The reason the lowercase matters is because the hash is different based on the case of the letter. It’s all good and fine to tell everyone to only use lowercase email addresses for their comments, but we have several years worth of archives here, and I’m not about to go back and fix the letter case of every comment to make the gravatars work.

Fortunately, php allows us to alter a string return before we hash it. That way, regardless of how the email address was saved in the database, it always gets sent to the encryption process as lowercase. Locate the gravatars.php plugin in your WordPress install, in the plugins folder. On line 17, you will find the following code:


.md5($comment->comment_author_email);

You need to add an additional modifier ’strtolower’ to the function, so that it looks like this (remember the extra parenthesis!):


.md5(strtolower($comment->comment_author_email));

Save, reload your page, and check it out. It should return gravatars for people who left comments, even if they used capitalization in their email address.

Of course, this doesn’t explain why Chad is the only guy left who can’t get his to work … but that’s a whole ‘nother post.

12 Responses to “Fixing Gravatars for WordPress”


  1. 1 Sharolyn

    How?… Wha?…

    Thank goodness there are people that think like you in the world.

    Especially the nice ones. (Not the Jimmy-Fallon-tech-support kind.)

  2. 2 Bobby

    (huff) Mooove.

  3. 3 Daniel Semsen

    Chad, you are SO high maintenance…

  4. 4 David

    Hi folks.
    Long time listener, first time caller.
    …Just testing my face. :)

  5. 5 Sharolyn

    Something’s wrong with my picture of Mike.

    ;)

  6. 6 michael lee

    what, the tie? the glasses? the overwhelming sexiness? what is it?

  7. 7 michael lee

    Here, Sharolyn. I’ll switch to the Mountain Man version.

    I love that I can just change my icon photos at will! We really do need to get Chad up and running on this.

  8. 8 Bobby

    me too.

  9. 9 Karen

    just checking to see if mine works

  10. 10 Chad

    Hey, lookie me!

    I’m gravalicious!

  11. 11 michael lee

    well well well, lookie there!

  12. 12 Paddy Wallbouncer

    Thanks for that hack. One of these days, I am going to have to install the plugin at theFutonPoncho.

Leave a Reply