Add Image to Default Avatar List in WordPress

How to Add Image to Default Avatar List in WordPress

in Comments
Google+ LinkedIn

When readers comment on your blog, WordPress uses the Gravatar platform to display a picture of the commenter next to his or her comment. If a commenter doesn’t have a Gravatar, or their email address isn’t associated with one, then WordPress displays the Mystery Man Gravatar as the default avatar in comments. WordPress also offers a couple of more generic avatars to choose from as your default avatar. Although it’s nice but sometimes you want to use your own unique custom avatar or may be your website logo for brand recognition. You can also read about how to display circular shape avatars in comments on your website.

In this article we will show you how to add your own image to default avatar list in WordPress, so you can select it as your default avatar for comment section. For avatar image, just make sure that image has equal width and height aka square-shaped and should not be large in size. A 100×100 pixel image is more than enough to be used as an avatar in most cases.

Upload avatar to you theme images folder and paste this code snippet to your functions.php file. Don’t forget to change image name and title before pasting this code in your theme.

// add image to default avatar list in wordpress
function wcs_add_image_default_avatars( $defaults ) {
    $new = get_stylesheet_directory_uri() . '/images/default-avatar.jpg';
    $defaults[$new] = "WPCodeSnippet";
    return $defaults;
add_filter( 'avatar_defaults', 'wcs_add_image_default_avatars' );

Share the love

If you like this snippet, share it with others!

One Reply on "Add Image to Default Avatar List in WordPress"

  1. Paal Joachim Romdahl

    Hey Nick

    Thank you for the code!
    I am for whatever reason getting a broken link as it seems to be looking at for the default avatar image and not inside my root images folder.

    Can one add multiple avatars using your code?

    I thought I would also check and see if you also have code for adding a browse (media library) ,upload field or url field to the user profile section.

    I am thinking of creating my own blog post on adding avatars without having to use a plugin.

    Have a great day!

Leave a Reply

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