WordPress Comment hack: Display Gravatar on non-pingback comment types

One of the reasons why I haven’t been paying much attention to this blog is the fact that I have started several new meant-to-monetize blogs over the past couple of months. Being very particular about my blog themes, I have been tweaking themes here and there while referring to the WordPress Codex for the template tags.

An issue I was trying to solve within this past hour was my Gravatars setting. I would like to display Gravatars only on normal comments left by visitors. I thought it makes no sense at all to display them on pingbacks, when all you get are those mystery man icons.

You’re suppose to add the following code to enable Gravatar support on WordPress comments:
<?php echo get_avatar( $comment, 32 ); ?>
The code by itself doesn’t solve my dilemma. In other words, that code will display Gravatars on all of my comments, regardless of whether they are normal comments, pingbacks, or trackbacks.

The following simple hack, though, does exactly what I wanted:
<?php if($comment->comment_type=='') { echo get_avatar( $comment, 32 ); } ?>

Surprisingly, I couldn’t find any online documentation concerning disabling Gravatars on pingbacks, so I had to look through some of my very own customized themes as well as a little reference to my WP database to understand how I can go about solving it.

Sweet, eh? Try it yourself. WP theme developers may find this code handy.

Socialize me:
  • StumbleUpon
  • Technorati
  • Digg
  • Bumpzee
  • SphereIt
  • Reddit
  • del.icio.us
  • Facebook
  • Google
  • TwitThis
  • Sphinn
  • Furl
These posts might interest you as well:
»Click to Comment plugin for your blog
»A smart and foolish move with WordPress plugins
»More WordPress plugin essentials at WebGrrrl.net

Tags: , ,

Check this out: For the Best WordPress Hosting, Use Bluehost For Just $6.95!

5 Comments »

Comment by Damien
2008-10-07 11:14:48

Thank you once again for an amazing Wordpress solution. You rock.

 
Comment by Downloadic
2008-10-19 09:58:16

Well, I havent heard that before. I think it is very useful, thanks…

 
Comment by Lisapeary
2008-10-24 17:03:51

Waiting for it to launch the new product. I wanted to know what are the new features available on it.

 
Comment by appleblogger
2008-10-26 11:47:05

thanks for that code. i believe that really a big help.

 
Comment by Linda Subscribed to comments via email
2008-10-28 00:52:03

Hi there, thanks for this! I’m new to WordPress, although I do create websites in old fashioned html. I appreciate your posting of this code, but am newbie enough that I don’t know where it gets added/changed. Would appreciate your guidance!

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.