我一直在研究过去几个小时,试图找到一种方法来禁用WordPress评论中的HTML。到目前为止,这一次一直出现在Google搜索结果的顶部:
// 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;
此代码不适用于最新版本的WordPress。我还发现了更多代码,但是没有用。那么如何在WordPress 3.6(最新版本)评论中禁用HTML?
答案 0 :(得分:3)
这删除了用户在评论中发布HTML(但出于某种奇怪的原因而不是链接)的能力:
add_filter( 'pre_comment_content', 'wp_specialchars' );
这消除了用户在评论中发布链接的能力:
remove_filter('comment_text', 'make_clickable', 9);
答案 1 :(得分:3)
要在评论中停用HTML标记,请将以下代码放入主题functions.php
:
add_filter('comment_text', 'wp_filter_nohtml_kses');
add_filter('comment_text_rss', 'wp_filter_nohtml_kses');
add_filter('comment_excerpt', 'wp_filter_nohtml_kses');