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.

Posted on 6 October, 2008 under Discovering WordPress and tagged with , ,

6 responses to “WordPress Comment hack: Display Gravatar on non-pingback comment types”

  1. Damien says:

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

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

  3. Lisapeary says:

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

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

  5. Linda says:

    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!

  6. […] 2008: I did a little research about a WordPress Comment hack: Display Gravatar on non-pingback comment types, and posted it since no one bothered doing so at that […]