@Guyra pointed out the quotation error and I've also noted that the get_currentuserinfo
is deprecated since WordPress 4.5.
You can hook the get_avatar
function and modify the output in your functions.php
file. Using get_avatar
is better and it will retrieve user avatar if the user is known, and gray man if it isn't. By hooking the function you can modify it and change how it works with unknown people:
add_filter( 'get_avatar','get_custom_avatar' , 10, 5 );
function get_custom_avatar($avatar, $author, $size, $default, $alt) {
if(stristr($author,"@")) $autore = get_user_by('email', $author);
else $autore = get_user_by('ID', $author);
if (isset($autore->ID) && $autore->ID > 0) {
// known people
return $avatar;
} else {
// unknown user
$avatar = "http://www.curious-howto.com/images/anonymous.jpg";
return "<img class='avatar' alt=\"".$alt."\" src='".$avatar."' width='".$size."' />";
}
}
Got this code and modified from here, there are also variations to get generated avatars from a different service instead of Gravatar.