K2 Quickie: Link Gravatars to Comment Author’s URL

May 11, 2006 · 18 comments

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

How smart is your Theme?  How good is your support? Check out ThesisTheme 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.

SEO Copywriting Made Simple
I used the Scribe WordPress plugin and service to optimize this blog post for SEO.

{ 8 trackbacks }

WordPress Station » Blog Archive » Gravatar Tip
May 11, 2006 at 10:36 pm
The Official Blog of Mark Vicuna
May 12, 2006 at 12:13 am
The Official Blog of Mark Vicuna
May 12, 2006 at 12:13 am
5ThirtyOne » Point Gravatars to their respective sites
May 12, 2006 at 1:09 am
How to link Gravatars to Comment Author’s URL at JohnTP’s Home
May 12, 2006 at 9:50 am
Bright Meadow » Sunday Roast: I’ve read the constitution and it does not protect ugly people
May 13, 2006 at 4:47 pm
K2 notes: Gravatar links at Decidedly Bored
May 27, 2006 at 1:48 am
how2 k2 - Comments at Cory Holt’s Weblog
June 21, 2006 at 9:31 pm

{ 10 comments… read them below or add one }

1 Laurence Anderson May 11, 2006 at 7:47 pm

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

Reply

2 Paul May 11, 2006 at 9:07 pm

Sweet, thanks for the tip !

Reply

3 Ben May 11, 2006 at 9:35 pm

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.

Reply

4 Colin D. Devroe May 11, 2006 at 11:05 pm

oh gosh, awesome tip!

Reply

5 Grace May 12, 2006 at 2:18 am

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

Reply

6 Zeo May 12, 2006 at 7:46 am

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

Reply

7 Dennis May 12, 2006 at 8:56 pm

Great stuff as usual Paul!

Reply

8 Olav May 16, 2006 at 7:42 am

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

Reply

9 weisheng May 27, 2006 at 2:04 am

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.

Reply

10 ch April 11, 2008 at 9:47 am

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! ;)

Reply

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: