这个方法好用或者方便的就是适合图片类或者需要截图解决问题的一些评论,直接复制黏贴图片链接就可以,那么缺点就是会把
所有评论里带有 .jpg .png .gif 图片的全部链接自动替换成显示图片,有可能只是想贴个链接可复制而已就变成了显示图片

其实只是用到了preg_replace()函数正则搜索和替换方式来实现这个功能,将下面代码添加到当前主题functions.php文件中即可

function comments_embed_img($comment) {
 $size = auto;
 $comment = preg_replace(array('#(http://([^\s]*)\.(jpg|gif|png|JPG|GIF|PNG))#','#(https://([^\s]*)\.(jpg|gif|png|JPG|GIF|PNG))#'),'<img src="$1" alt="评论" style="width:'.$size.'; height:'.$size.'" />', $comment);
 return $comment;
}
add_action('comment_text', 'comments_embed_img', 2);