duskosobic
1/26/2017 - 9:57 AM

How to Display Custom Avatar in Comments For Users Without Gravatar. you can replace it with some sensible image like your blog logo or some

How to Display Custom Avatar in Comments For Users Without Gravatar. you can replace it with some sensible image like your blog logo or some other images to make it unique. So here is how to do it.

Create a 80px*80px squared .png image with file name custom-avatar.png and upload it your current themes images folder. If there is no such folder then create it and upload the logo in it.

Now insert the following lines of code at the end of your current theme’s functions.php.

Save the file and head over to Settings >> Discussion. At the end of the settings page you can find your uploaded image like below.

Select “My default Avatar” and save the settings. Thats it you are good to go with.

Your default avatar will be used in comments and author bio when user doesn’t have gravatar.

<?php

add_filter( 'avatar_defaults', 'custom_avatar' );
function custom_avatar($avatar_defaults){
	$custom_avatar = get_stylesheet_directory_uri() . '/images/custom-avatar.png';
	$avatar_defaults[$custom_avatar] = "My Default Avatar";
	return $avatar_defaults;
}

?>