教你如何禁用 WordPress 评论里的html标记
用WP的博主们应该都遇到过评论里带html标记链接的,很是烦人,因为wordpress 默认的评论可以包括各种html标记语言,如超链接、加粗加斜、表单等等,其实说起来,这应该是一个不错的功能,但很多人不去好好的使用,使用这个功能在评论友好的同时也把垃圾评论留言带来了,这些垃圾留言真的很讨厌,所以有时候禁用 wordpress 评论里的html标记是非常非常有必要的。今天闲的没事,网上找了教程,马上给大家共享出来:
禁用 wordpress 评论的HTML标记:
在你当前使用的wp主题模板中的functions.php文件(如果没有就自己创建一个)中的<?php和?>之间添加以下代码:
// 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( "'", ''', $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( ''', "'", $comment_to_display );
return $comment_to_display;
保存文件上传后,WP评论里的HTML标记就会失效。哈哈,不错吧
转载文章请注明,转载自:妍熙饭 [http://www.yanxifan.com]