K2 Quickie: Link Gravatars to Comment Author's URL

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.