有时发表评论需要添加图片,而WordPress本身并不具备评论贴图功能,可以将下面的代码添加到当前主题functions.php文件中:
add_action('comment_text', 'comments_embed_img', 2);
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;
}
添加上述代码后,在发表评论时直接粘贴图片链接地址即可。
温馨提示:本文最后更新于
2024-07-10 14:23:19
,某些文章具有时效性,若有错误或已失效,请 联系我们 反馈。👋 感谢您的观看!
© 版权声明
THE END