广告
返回顶部
首页 > 资讯 > CMS >WordPress评论中禁止HTML代码显示的方法
  • 759
分享到

WordPress评论中禁止HTML代码显示的方法

WordPress评论禁止HTML代码显示方法 2022-06-12 02:06:45 759人浏览 独家记忆
摘要

本文实例讲述了WordPress评论中禁止html代码显示的方法。分享给大家供大家参考。具体分析如下: 使用WordPress的朋友会发现如果我们开户了博客评论会经常看到大量的垃圾广告,带连接了,那么我们要如何禁止用户输

本文实例讲述了WordPress评论中禁止html代码显示的方法。分享给大家供大家参考。具体分析如下:

使用WordPress的朋友会发现如果我们开户了博客评论会经常看到大量的垃圾广告,带连接了,那么我们要如何禁止用户输入html标签原样输出,而不显示呢,下面我来给大家介绍.

html标题无非就是由“<”、“>”组成了,我们可以反它转换成“&lt;”、“&gt;”,这样通过HTML编译,自动变成了“<”、“>” 我们也可以直接替换掉了

找到一国外人的代码,搞定了,不过不一定他是原作者,在functions.PHPphp代码里加入如下代码:


复制代码代码如下://禁用wordpress评论html代码

// This will occur when the comment is posted

function plc_comment_post( $incoming_comment ) {

// convert everything in a comment to display literally

$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);

// the one exception is single quotes, which cannot be #039; because WordPress marks it as spam

$incoming_comment['comment_content'] = str_replace( "'", '&apos;', $incoming_comment['comment_content'] );

return( $incoming_comment );

}

// This will occur before a comment is displayed

function plc_comment_display( $comment_to_display ) {

// Put the single quotes back in

$comment_to_display = str_replace( '&apos;', "'", $comment_to_display );

return $comment_to_display;

}

add_filter( 'preprocess_comment', 'plc_comment_post', '', 1);

add_filter( 'comment_text', 'plc_comment_display', '', 1);

add_filter( 'comment_text_rss', 'plc_comment_display', '', 1);

add_filter( 'comment_excerpt', 'plc_comment_display', '', 1);

希望本文所述对大家的WordPress建站有所帮助。

--结束END--

本文标题: WordPress评论中禁止HTML代码显示的方法

本文链接: https://www.lsjlt.com/news/32249.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作