Set Custom Gravatar Image As Default In WordPress

If you use the default WordPress comments on your WordPress blog, then you would most probably be displaying the images of the commenters along with their comment. This image is displayed using a third-party service called Gravatar.

For people who do not have a Gravatar account, Gravatar displays a default image, which the site administrator can choose from the WordPress dashboard (Settings > Discussion). But there’s a limitation though. Gravatar does not allows you to set any custom image as the default image for WordPress comments, but we have a small snippet to help you with this.

Set Custom Image As Gravatar Default

Adding the below code to your functions.php will make the image gravatar.jpg stored in your active theme’s directory under the folder images as the default image for Gravatar.

function default_gravatar ($avatar_defaults) {     $myavatar = get_bloginfo('template_directory') . '/images/gravatar.jpg';     $avatar_defaults[$myavatar] = "Default Gravatar";     return $avatar_defaults; } add_filter( 'avatar_defaults', 'default_gravatar' );
Related Post