Archive Old post. Originally published 4 July 2012 on the WordPress version of this site. Preserved here for the search engines and the curious. Old me had opinions.
Developer 2 min read

Quick Tip: Custom Default Gravatar in WordPress

WordPress Gravatar SupportWordPress gives us lots of little things we can tweak to our own needs. WordPress out of the box includes Gravatar support and has a number of ways you can use this in your themes and plugins.

The usual situation is attaching a Gravatar to when someone posts a comment (as happens on my site) if that person does not have a Gravatar account you can define in the Admin Dashboard what should be shown. You get a few choices which aren’t bad but you can create your own custom Gravatar to put a small but personal touch to your site.

Firstly create an image to use, it should be 70px x 70px and save it as a JPEG. You can stick it anywhere you like in your theme folder setup but I’m sticking it in /mytheme/images.

Next we need to tell WordPress about it. Open up your themes functions.php and stick in the following code, modifying it to fit your needs.

function custom_gravatar ( $avatar_defaults ) {
$mytavatar = get_theme_directory_uri . '/images/avatar.jpg'; //Make Sure you change this depending on your image name and location
$avatar_defaults[ $mytavatar ] = 'My Custom Gravatar'; //This is what is displayed in the Admin settings when Picking your Default Avatar
 return $avatar_defaults;
 }

add_filter( 'avatar_defaults', 'custom_gravatar'  );

That’s it. It’s only a few lines of code and you can really make a difference.


Filed under Developer. No comments, on purpose.