I recently decided to add gravatars to my theme, so I launched a search for anyone’s tips on best positioning of the gravatar code within Cutline. Since I didn’t find anything, I did it on my own–but I thought I’d share with you exactly which code to put where to get gravatars on Cutline positioned like mine. As a bonus, a small section at the bottom shows you how to create a add a custom default gravatar for your site. You’ll see that commenters without gravatars get a ghosted black-and-white BC avatar.

(Note, if you want your gravatars to be bigger or smaller, change the ‘50′ to ‘40′ or ‘60′ or whatever size you want.)

2. Styling the avatars in style.css or custom.css.

a) If you’re playing by the Cutline rules and have made all your changes in the custom.css stylesheet (or haven’t yet made any changes), open custom.css. If you’ve already hacked style.css to shreds anyway, open style.css.

This will style your gravatars with 4 pixels of padding on either side, then a 1px light-gray border, then a left/right margin to set them off. They’ll sit on the top left of your comments and the comment will wrap around them.

3. Turning on Gravatars.

Now your theme is set up for gravatars, but they may not be turned on. Navigate to Settings -> Discussion and enable gravatars, select the highest rating you’ll display, and choose a backup. Save those settings and watch the gravatars show up in your comments section.

Adding a Unique Default Gravatar

Now that your site has gravatars, you’ll find out just how many of your commenters don’t have them. You can select a mystery man, the gravatar logo, a blank space, or some randomly-generated icons to fill the space. Or you can create a special gravatar for your site. For example, I took the BlogCrafted gravatar, turned it black-and-white, and ghosted it. It shows up when people leave comments and aren’t signed up with gravatars, that’s what shows up for them.

Turns out that adding a gravatar that’s unique to your site isn’t hard at all. First you have to come up with a default avatar. In my example, it’s saved as defaultgravatar.jpg. If you use a different filename, be sure to change that in the code.

Upload the gravatar to the images folder of your theme directory (in Cutline, it’s called “images,” if your theme is different, please modify the code below to reflect its image folder name).

Then back in the Theme Editor area, navigate to functions.php (called Theme Functions). Directly under the:

1) make sure the image location /images/defaultgravatar.jpg is the same as your image’s location. In this case, it’s in the images folder of your theme and called defaultgravatar.jpg. Make changes as appropriate.

2) “Unique Default Gravatar” can be changed to whatever you want to call it.Don’t delete the quotation marks or the semi-colon that comes after.

Otherwise, unless you know PHP, you don’t want to mess with this.

Turn it on. Now go to Settings -> Discussion. The new gravatar should appear in the list of default options. Select it, save, and voila! (if you’re using a caching plugin, you may have to clear it for this to take effect.)

Now there’s only one thing left to do–enjoy your blog’s new gravatars.

A special thanks to the helpful Build Internet article I found on changing default gravatars. Check it if you’d like to know how the code works and see images of what it’ll look like once you’ve done it.