Deprecated: pk_vd_gt_validate(): Implicitly marking parameter $args as nullable is deprecated, the explicit nullable type must be used instead in /home2/xzgzscom/public_html/xzgzs.com/wp-content/themes/wordpress-theme-puock-2.8.12/inc/fun/core.php on line 1290
WordPress 评论中嵌入图片 - 小志工作室 WordPress 评论中嵌入图片 – 小志工作室

WordPress 评论中嵌入图片

有时发表评论需要添加图片,而WordPress本身并不具备评论贴图功能,可以将下面的代码添加到当前主题functions.php文件中:

WordPress 评论中嵌入图片WordPress 评论中嵌入图片WordPress 评论中嵌入图片WordPress 评论中嵌入图片
  1. add_action(‘comment_text’, ‘comments_embed_img’, 2);
  2. function comments_embed_img($comment) {
  3.     $size = auto;
  4.     $comment = preg_replace(array(‘#(http://([^s]*).(jpg|gif|png|JPG|GIF|PNG))#’,’#(https://([^s]*).(jpg|gif|png|JPG|GIF|PNG))#’),'<img src=”http://zmingcx.com/$1″ alt=”评论” style=”width:’.$size.’; height:’.$size.'” />’, $comment);
  5.     return $comment;
  6. }

添加上述代码后,在发表评论时直接粘贴图片链接地址即可。

具体效果可以在本文留言并贴图。

正文完
 0