I am looking for a solution to output nothing instead the default avatar when a user does not have any avatar.
I am currently using this line. I looked at the function and the only thing I got so far is to use blank
as default avatar but its still occupies space and I do not want that.
echo get_avatar( get_the_author_meta( 'ID' ), 70, 'blank', __( 'avatar', 'bla' ) );
Sidenote: Even that blank avatar gets pulled from Gravatar, I think this is ridiculous.
5 Answers
You can use the get_avatar
filter to change the output or avatar_defaults
to add new image that can be placed on your server.
Here is an example code for adding new avatar that you can set as default from the Settings > Discussion page.
add_filter( 'avatar_defaults', 'add_new_gravatar_image' );
function add_new_gravatar_image($avatar_defaults) {
$myavatar="http://yoursite.com/image.png";
$avatar_defaults[$myavatar] = "Default Gravatar";
return $avatar_defaults;
}
And if you want to change the output, you have an example on the documentation page for get_avatar.