To disable WordPress from displaying avatars in comments WordPress provides a option in Settings ยป Discussion to disable avatars.
But the issue is that this option disables avatar throughout the website. Therefore avatar on author info box is not displayed.
So I have written a code snippet which disables avatar only on comments template. This code overrides the above option too.
{
global $in_comment_loop;
if(isset($in_comment_loop))
{
if($in_comment_loop == true)
{
return "<img alt='{$alt}' src='' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}
else
{
return $avatar;
}
}
else
{
return $avatar;
}
}
add_filter("get_avatar" , "disable_comment_avatar" , 1, 5);
You can inject this code as WordPress plugin or else you can paste this code in your theme’s functions.php file.
This code interpret get_avatar
functions’s return value. This function is used by WordPress core’s comment template to retrieve avatar’s HTML i.e., img
tag with src
attribute.