How to Use Custom Image as Default Avatar in WordPress Comment (Without Plugin)

As we already know, WordPress associates an avatar with your email address, and Gravatar powers user avatars in WordPress. Your Gravatar account will be linked automatically with your WordPress if it registers with the same email address. So, when you’ve added an avatar on Gravatar, you will see the same avatar when you comment on blogs, post content, and on any other site using Gravatar’s feature.

This article will show you how to use a custom image as the default avatar in WordPress comment without using Gravatar and the help of any plugin. In other words, you can change your default avatar with any image you want without associating it with your email address and Gravatar.

Steps to Use Custom Image as Default Avatar without associates with Gravatar

Step 1: Upload the Image

First, choose the custom image you want to use as a default avatar, then upload it to your WordPress Media library.

On your WordPress dashboard, navigate to Media -> Add New. Upload your desired image by clicking the Select Files button. Once the image is uploaded, copy the URL by clicking the Copy URL to clipboard button.

Note: You can paste the URL into a text editor, such as Notepad or TextEdit. It will be helpful to step later.

Step 2: Add the Code Snippet to the functions.php File

Next, we will add the simple PHP snippet to the functions.php file to use a custom image as a default avatar. Here is snippet.

add_filter( 'avatar_defaults', 'wpb_new_gravatar' );
function wpb_new_gravatar ($avatar_defaults) {
$myavatar = 'ADD YOUR URL HERE';
$avatar_defaults[$myavatar] = "Default Gravatar";
return $avatar_defaults;

But, before adding that PHP snippet to the functions.php file, you must add the image URL you upload in step one into the PHP snippet above. Paste the image URL to that snippet in line three between the apostrophe by replacing “ADD YOUR URL HERE.”

Once you add the URL to the PHP snippet, copy the snippet and paste it into the functions.php file.

On your WordPress dashboard, go to Appearance -> Theme File Editor.

Once enter the Theme File Editor page, select the functions.php and paste the PHP snippet at the end of the functions file content.

Next, update the theme file by clicking the Update File button.

Note: If you are afraid of breaking your site after adding the new function to the functions.php file, you can create a child theme or create a custom plugin. Read here to learn more.

Step 3: Default Avatar Setting

Alright, now we’re moving on to the last step. Here, we will set our new avatar as a default avatar. When you’ve added the PHP snippet to the functions.php file, your default avatar is already changed, but it’s not already active yet, and this is what we want to do.

On your WordPress dashboard, go to Settings -> Discussion. Afterward, scroll down to the Default Avatar section and select your new avatar as default. Once you set it, apply the changes by clicking the Save Changes button.

That’s it. Now your new avatar is already active. You can see your profile or comment on your site for your new default avatar.

The Bottom Line

This article shows how easily you can use a custom image as a default avatar in your WordPress without using Gravatar and the help of any plugins. By adding a PHP snippet into the functions.php file, you can still do that; even by default, WordPress doesn’t have the option to use a custom image as a default image without using plugins or Gravatar.

This page may contain affiliate links, which help support our project. Read our affiliate disclosure.
Akbar Padma

Akbar Padma

Akbar is a WordPress expert and a writer staff at WPPagebuilders. He mainly writes about Gutenberg, Elementor, Divi, and other WordPress page builders.
Want to save yearly expense up to $219? why not?

1 thought on “How to Use Custom Image as Default Avatar in WordPress Comment (Without Plugin)”

Leave a Comment