Unless otherwise indicated, the code snippets you see below should be placed into your theme’s functions.php file.
Here is the code to display a custom Gravatar on your site:
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Display a custom Gravatar
add_filter( 'avatar_defaults', 'sp_gravatar' );
function sp_gravatar ($avatar) {
$custom_avatar = get_stylesheet_directory_uri() . '/images/gravatar.png';
$avatar[$custom_avatar] = "Custom Gravatar";
return $avatar;
}