How to add a default gravatar on WordPress

Globally Recognized Avatar or Gravatar is a WordPress’s avatar system which allows an avatar image displayed next to comments made by the user on any WordPress site. The image icon can be a brand representing your company and brand. WordPress comes with a series of default gravatar; this guide shows you how to upload a custom image and use it as the default gravatar in WordPress instead of the default image placeholder.

Upload an image for  gravatar in WordPress

To upload image to Media library,  follow these steps:

  1. Log in to your WordPress site with an administrator account.
  2. On the Dashboard in the left sidebar, click Media:

  3. Click on Add New, and then click on Select Files to select and upload an gravatar image:

  4. The new gravatar image is listed on the Media Library:

  5. Click on the image, copy the File URL. This URL will be used in the code snippet in the upcoming sections:

Add a default gravatar in WordPress

To add a default gravatar,  follow these steps:

  1. On the Dashboard in the left sidebar, click Appearance, and then click Theme Editor:

    You will not be able to roll back to your earlier Theme configuration after any edits. Make a copy of  the Theme file before proceeding with the edits.
  2. On the Theme Editor , select the Theme you want to edit from the dropdown:

  3. The files for this selected theme are listed on the right column under Theme Files. Click on the file named “functions.php”:

  4. Insert the following code to the end of functions.php file:

    add_filter( 'avatar_defaults', 'custom_gravatar' );
    
    function custom_gravatar ($avatar_defaults) {
    
    $myavatar = 'http://YOUR_WORDPRESS.COM/images/custom_gravatar.png';
    
    $avatar_defaults[$myavatar] = "Default Gravatar";
    
    return $avatar_defaults;
    
    }
  5. Copy the URL from Step 5 in Upload an image for  gravatar and replace URL for $myavatar in the function.Click Update File button to update the file.

    add_filter( 'avatar_defaults', 'custom_gravatar' );
    
    function custom_gravatar ($avatar_defaults) {
    
    $myavatar = 'http://YOUR_WORDPRESS.COM/images/custom_gravatar.png'; //replace this with your the image URL
    
    $avatar_defaults[$myavatar] = "Default Gravatar";
    
    return $avatar_defaults;
    
    }

View the default gravatar in WordPress

To view the default gravatar in WordPress, follow these steps:

  1. On the Dashboard in the left sidebar, click Settings, and then click Discussion:

  2. Scroll down to the Default Avatar section to view the new default Avatar:

  3. Select the new gravatar and click on Save Change:

  4. The gravatar will be displayed beside the username:

Get Managed WordPress Hosting

Article Details

Other Articles in This Category

Show More

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.