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.
PaulStamatiou.com runs on the Thesis Theme for WordPress
Thesis is the search engine optimized WordPress theme of choice for serious online publishers. If you’re a blogger who doesn’t understand a lot of PHP, Thesis will give a ton of functionality without having to alter any code. For the advanced, Thesis has incredible customization possibilities via Thesis hooks.
With so many design options, you can use the template over and over and never have it look like the same site. The theme is robust and flexible enough not only to accommodate a site like PaulStamatiou.com, but also to enable the site to run far more efficiently than it ever has before.







{ 8 trackbacks }
{ 10 comments… read them below or add one }
Thanks Paul, I implemented this on my site :).
Sweet, thanks for the tip !
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.
oh gosh, awesome tip!
Nice tip Paul :)
will implement it in my blog soon.
Haha this is funny. Last month I suggest to Mike and Chris about removing the gravatar.com URL.
Great stuff as usual Paul!
Thanks, a great idea. Seems so obvious now though.. :)
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.
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! ;)