Using Gravatars in WordPress

I'll show you how to display an author's gravatar next to post titles, and customize the default Gravatar for commenters who don't have one already.

Gravatars are Globally Recognized Avatars . They are built into WordPress' comments by default, but there are some ways you can customize them. I'm going to outline two customizations I recently did for clients.

Note that the hooks I use here is specific to Thesis . If you're using Genesis you should be able to replace the hooks with genesis ones ( genesis_before_post_title instead of thesis_hook_before_headline ...). If you're not using a framework, you can skip the functions/hooks and drop the code directly in your theme.

Displaying an author's gravatar next to postsIf you have multiple authors on your blog, you might like to display their picture next to posts. We'll use the WordPress function get_author() (more information on this in the WordPress Codex ).

First Function - Displays gravatar next to Features on homepage and individual post pages.


Second Function - This adds the gravatar next to the teasers (if you're using them).


Adding your own default Gravatar

If your commenters don't have a Gravatar, WordPress will show a default one. You can set your own default Gravatar (like your logo), by adding the following code to your functions.php file.

No comments yet