Search
Close this search box.

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.
Picture of 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 turn your WordPress knowledge into revenue? OF COURSE!

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

Leave a Comment

Share This
Hey 👋🏻
Do you have a WP blog?
If so, you may need these. All the resources you need to grow your blog.

Your popup content goes here

50%

Where should we send the template?

After entering your email address, you will be added to our newsletter subscribers. You can unsubscribe anytime.

Want to Build Passive Income Like the One on the Screenshot Below?

Click the button on the right side to learn how 👉🏻
5 easy steps to turn your WordPress knowledge into monthly recurring revenue.

Click the above button to close the popup.