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 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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Mojowill Avatar

Who the Hell am I?

I'm Will, a full time web developer, geek and musician. I develop using PHP and MySQL and spend most of my time working with WordPress or CakePHP. When I'm not buried in code I'm gaming, cooking or writing and recording music in my studio. I like sci-fi, pancakes and coffee and am totally prepared for the zombie apocalypse...

Stalk me on these other sites...

Why not be super creepy and check me out on all these other sites, I think they call it social media?

%d bloggers like this: