WORDPRESS:评论无法使用 img 标签

  • 🎉Wordpress
  • 1999 阅读
  • 2018年10月18日
  • 0 条评论
  • 全文共105字, 阅读大约需要1分钟
  • 搜索引擎已收录

首页 / 🎉Wordpress / 正文

AI摘要
Gemini Pro
此内容根据文章生成,并经过人工审核,仅用于文章内容的解释与总结
反馈

WP默认非管理员在发表评论时无法使用 img 标签,特别不美,两种方法修改

一、修改主题法 把下面的代码加到主题的 functions.php 就可以了:

function sig_allowed_html_tags_in_comments() {
   define('CUSTOM_TAGS', true);
   global $allowedtags;
   $allowedtags = array(
      'img'=> array(
         'alt' => true,
         'class' => true,
         'height'=> true,
         'src' => true,
         'width' => true,
      ),
   );
}
add_action('init', 'sig_allowed_html_tags_in_comments', 10);

二、修改核心代码 找到

wp-includes/kses.php文件,搜索?$allowedtags = array(大概 424 行,在下面添加:

'img' => array(

'src' => true,
'alt' => true,
'class' => true,
'height'=> true,
'width' => true,

),

另外,下面是让 WP 识别评论区图片链接的代码,加到

functions.php

add_action('comment_text', 'comments_embed_img', 2);
function comments_embed_img($comment) {

$size = auto;
$comment = preg_replace(array('#(https://([^\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;

}

上面两种方法选择一种就即可。

 赞  赏

如果觉得我的文章对你有用,请随意打赏

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开  或者  扫一扫,即可进行扫码赞赏哦

本文来自投稿,不代表本站立场,如若转载,请注明出处。
本文最后更新于2020年08月11日17时50分47秒,已超过1354天没有更新,若内容或图片失效,请留言反馈
本文链接:https://nie.su/archives/273.html(转载时请注明本文出处及文章链接)
作品采用:《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权

发表评论

博主 - <?php $this->author->screenName(); ?>

love2wind

记录生活,分享世界