Twitter: in profession communication class.. talking about typography today, ohh
Subscribe via RSS or email  #error


K2 Quickie: Link Gravatars to Comment Author’s URL

May 11, 2006 in ,

Wouldn’t it be nice if the gravatars on your K2 and WordPress-powered blog actually linked to the author’s website instead of gravatar. For those out of the loop, gravatars are globally recognized avatars. Once a person has registered their email address with gravatar.com and paired it with an avatar, they can go around commenting on gravatar-enabled blogs (most blogs are these days) and have their unique avatar appear adjacent to their insightful comment.

By default K2 links each gravatar, regardless of comment author, to the gravatar website. While this does help promote awareness about gravatars and spread the word, it’s not exactly helpful for those wishing to access that commenter’s site. Luckily this can easily be changed and add that extra bit of usability to your blog.

Fire up your FTP application and navigate to your K2 directory. Open up comments.php in your favorite text editor, whatever it may be.

Look for this snippet (around line 60):

<?php if (function_exists('gravatar')) { ?><a href=”http://www.gravatar.com/” title=”What is this?”><img src=”<?php gravatar(”X”, 32, “”); ?>” class=”gravatar” alt=”Gravatar Icon”/></a><?php } ?>

and replace it with this chunk:

<?php if (function_exists('gravatar')) { ?><a href=”<?php comment_author_url(); ?>” title=”<?php comment_author(); ?>’s website”><img src=”<?php gravatar(”X”, 32, “”); ?>” class=”gravatar” alt=”Gravatar Icon” /></a><?php } ?>

In the last bit of code, I made use of two WordPress tags; comment_author_url and comment_author. The first outputs the commenter’s url while the second tag outputs the commenter’s name, as expected.

Promote this article on various sites or email to your friends:     



18 Comments

  1. Thanks Paul, I implemented this on my site :).

  2. Sweet, thanks for the tip !

  3. That’s great Paul! Thanks. I’ve been thinking about how to do something like this for a few weeks now but never got around to trying it, you saved me a bit of work.

  4. Nice tip Paul :)
    will implement it in my blog soon.

  5. Haha this is funny. Last month I suggest to Mike and Chris about removing the gravatar.com URL.

  6. Great stuff as usual Paul!

  7. Thanks, a great idea. Seems so obvious now though.. :)

  8. I’ve tweaked the code a little so my gravatars are only linked when the commenter leaves an URL. The code is available on my blog.

  9. The code for this section has changed in the upgrade to WP 2.5

    It might be useful to have another chuck for us that upgraded! ;)

  1. My blog now supports GRAvatar…

    I’ve added GRAvatar support to the comments functionality of this blog. If you don’t have one and don’t want one, no worries—you don’t need them. If you already have one, or want one, they’re free!Basically it works like this: if you leav…

  2. My blog now supports GRAvatar…

    I’ve added GRAvatar support to the comments functionality of this blog. If you don’t have one and don’t want one, no worries—you don’t need them. If you already have one, or want one, they’re free!Basically it works like this: if you leav…

  3. [...] Paul Stamatiou does the grunt and provides a little code snippet for improving a Gravatar enabled blog. By default, the gravatar plugin redirects clicks to Gravatar.com. A simple copy n’ paste will have Gravatars on your site redirected to their respective authors page. <?php if (function_exists(’gravatar’)) { ?><a href=”<?php comment_author_url(); ?>” title=”<?php comment_author(); ?>’s website”><img src=”<?php gravatar(”X”, 32, “”); ?>” class=”gravatar” alt=”Gravatar Icon” /></a><?php } ?> [...]

  4. [...] Like the tip? Don’t thank me, thank Paul Stamatiou. Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages. [...]

  5. [...] The ever knowledgeable Paul has a great how-to to make gravatars link to comment authors URL as opposed to the gravatar site. I’ve lost track of the times I’ve automatically clicked on a gravatar (the little picture that appears next to some peoples names) thinking it will take me to the commenters site, only to be greeted by the gravatar site instead. So I can see the plus side in this - it spreads the word about gravatars and is certainly the way I worked out how to get one - but at the same time it is very counter-intuitive for the user. Which would explain why I implemented this little change within five minutes of reading the article [...]

  6. [...] Paul Stamatiou previously posted a quick K2 hint on how to link gravatars to the comment author’s website. I’ve tweaked his code so that gravatars are linked only when a commenter leaves an URL. [...]

  7. [...] If your looking for tutorials on how to modify how gravatars are displayed, I found a great article on Paul Stamatiou’s blog that talks about how to change the link of the gravatar image. Instead of it linking to the gravatar website, it will link to the commenter’s website (if they have one). I thought this was pretty cool so I’ll share it with you. [...]

Post a comment, receive Stammy points.


Send a trackback.


  • If you plan on posting code, run it through Postable first.
Copyright © 2005 - 2008 PaulStamatiou.com  Privacy Policy - Terms of Service Can't spell my name? Use PSTAM.com. Go back up ↑.