默認情況下,WordPress允許注釋中包含某些HTML標記,例如 a 、 e 、strong等。如果您注意到許多垃圾郵件注釋也包含這些標記。大多數垃圾郵件評論是由使用HTML標記的機器人和腳本發出的。如果你只是在WordPress評論中禁用HTML,它可以防止大量的垃圾郵件。在本教程中,我們將向您展示如何禁用WordPress評論中的HTML標記。
本教程將僅禁用活動的HTML標簽。因此,某人仍然可以發布類似的內容:
& lt; a> & lt; em> & lt; strong>
它會顯示出來,但是標簽不會起作用。所以如果有人使用strong標記,它不會加粗文本。此外,沒有多少垃圾郵件機器人有時間這樣做,因為這種方式占用了大量的時間,這對他們沒有好處。
您只需打開functions.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;
}
如果您不想自己手動添加這段代碼,那么原作者還提供了一個可以下載的插件。只需安裝并激活Peter的文字評論插件。
這種方法之所以更好,是因為它不需要更改核心文件。如果你想編輯你的核心文件,你可以去wp-includes/kses.php編輯代碼。





