• Skip to primary navigation
  • Skip to main content
  • Skip to footer
Alex Mustin
  • About
  • Services
  • WordPress Tips
  • Websites
  • Plugins
  • Contact Me
Alex Mustin
  • About
  • Services
  • WordPress Tips
  • Websites
  • Plugins
  • Contact Me
Alex Mustin

Alex Mustin

  • About
  • Services
  • WordPress Tips
  • Websites
  • Plugins
  • Contact Me
  • About
  • Services
  • WordPress Tips
  • Websites
  • Plugins
  • Contact Me

Show Custom Avatar Images in Comments

April 8, 2015 in Code Snippets, Development

Gravatar is a great service by Automattic, the folks behind WordPress. In Gravatar, you designate your online profile picture one the one website. Whenever you sign in with this address on another website, it can display your universal Gravatar image.

In the default WordPress Comment system, each comment will be displayed alongside an image from the Gravatar service. If the user has not signed up with the service before or is unknown, then the WordPress page will display a random image. If you want to customize what this random image is, all you need to do is add the following lines of code to your functions.php file:

add_filter('avatar_defaults', 'add_custom_gravatar');
function add_custom_gravatar($avatar_defaults) {

    $myavatar = get_bloginfo('template_directory') . '/images/custom-gravatar.png';
    $avatar_defaults[$myavatar] = "Custom Gravatar";
    return $avatar_defaults;
}

In the above example, the ‘custom-gravatar.png’ image would be located inside the Theme’s images folder: /yourtheme/images/custom-gravatar.png

When creating your Custom Avatar image, the dimensions should be: 80px x 80px square.

Filed Under: Code Snippets, Development

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer

Developing creative WordPress websites and solutions for companies of all sizes since 2008.

SOLUTIONS

  • One-Page Website
  • Maintenance Service

RESOURCES

  • Client Login
  • WordPress Tips
  • Mastodon

© 2025 Alex Mustin