Custom Default Avatar for Comments

Requirements

  • Must be using a self-hosted WordPress platform.
  • Must be able to edit your functions.php theme file (or create a new one if one does not already exist).

What We’ll Be Creating

As you may know, on WordPress, in the “Discussion” settings, you have the option of setting a default avatar. This avatar will appear whenever someone who doesn’t have their own avatar (usually from Gravatar.com) posts a comment on your blog. The default avatars available are… not that attractive. Here are some of the options:

Default Avatar Examples

If you really want to go all out personalizing your blog, you may want to set your own custom default avatar! Perhaps to your site logo or to something more bookish. Well let’s get started!

Step 1: Create & Upload Your Custom Avatar

The first step is to create your avatar using Photoshop or any other image editing program. Be sure to save the avatar in a GIF, PNG, or JPG format. Then, you need to upload the image to your site. You can save it wherever you want — in the theme file or just upload it regularly using WordPress’s built in media uploader.

Once you’ve done that, you need to locate and open your functions.php file. This is located in your theme directory. Make sure your functions.php file is enclosed in php tags like so:

<?php

//Code here

?>

If it’s not, you’ll have to add those in yourself.

Then, paste the following code into the body of your functions.php file (inside the php tags):

//Custom Gravatar
add_filter( 'avatar_defaults', 'newgravatar' );
function newgravatar ($avatar_defaults) {
	$myavatar = 'http://www.custom-avatar-url.png';
	$avatar_defaults[$myavatar] = "Your Avatar Name";
	return $avatar_defaults;
}

Obviously you’ll have to change the URL I have in there to the URL of your own custom avatar.

Then save your functions.php file, navigate back to the WordPress » Settings » Discussion page, and if you followed the instructions correctly, your new image should be listed as an option for your default avatar! Simply select your new avatar, save your settings, and you’re done!

Custom Default Avatar for Comments

Photo of Ashley
I'm a 30-something California girl living in England (I fell in love with a Brit!). My three great passions are: books, coding, and fitness. more »

Don't miss my next post!

Sign up to get my blog posts sent directly to your inbox (plus exclusive store discounts!).

You might like these

8 comments

    1. It should resize, but I still recommend that you manually shrink it down, at least close to what would be displayed on your blog. 🙂

  1. Oh neat, thanks for pointing me to this post Ashley. So in essence, when we use this it would only show the custom avatar for the folks who don’t already have a Gravatar setup right?

    p.s. used the CommentLove plugin on my site, and it works great! Soon enough I’ll actually follow the tut and build upon it to maybe include some other settings, or definitely at-least style it to match my current site more. Thanks for sharing it 🙂

    Sasha-Shae recently posted: Fly Natural: Shanita
    1. Yes that’s right. 🙂 This is the default if they don’t already have their own custom one.

      I’m so glad you’re liking the Comment Love plugin! Woohoo!

Recent Posts

    Random Posts