Change Default WordPress Gravatar in Comments

by Hiroshi on December 21, 2009

in Hacks, WordPress

If you use a plugin to add avatars to your blog, there might be a setting in the plugin’s options page for choosing the default avatar. If you use WordPress 2.5+, then you probably use a template tag like the following for your avatars.

<?php echo get_avatar( $comment, 32 ); ?>

You can easily modify this code to show a default customized gravatar to appear if the comment author has no gravater to show.

Just add a comma after the 32 (The pixel size of the image, if you want to change that while you’re at it!), and paste in the URL to your image. e.g.

<?php echo get_avatar( $comment, 80, 'https://www.yourblogaddress.com/my-gravatar.jpg' ); ?>

Now the comments on your posts will have a much nicer image that draws less attention, promotes recognition of your logo, and as so few blogs have a unique default avatar, it shows your attention to detail.

Related Posts

Previous post:

Next post: