By default most of the time WordPress comments will include a “gravatar” (linked to the user’s email address) when displaying comments, using WordPress built-in function get_avatar()
.
You can hook a custom function to the get_avatar
filter to return another image.
Something like this should do the trick for your use case: it filters 'get_avatar'
and returns an image with the comment author’s website URL if it is set. Add this to your theme (or child theme) functions.php:
add_filter( 'get_avatar', 'wpse310726_custom_avatar', 1, 5 );
function wpse310726_custom_avatar( $avatar, $id_or_email, $size, $default, $alt = null ) {
$comment_author_url = get_comment_author_url();
if ( '' !== $comment_author_url ) {
$avatar = "<img alt="{$alt}" src="https://wordpress.stackexchange.com/questions/310726/{$comment_author_url}" class="avatar avatar-{$size} photo" height="{$size}" width="{$size}" />";
}
return $avatar;
}