默認情況下,wordpress 允許在評論中包含某些 html 標簽,例如 等。如果您發現很多垃圾評論也包含這些標簽。大多數垃圾郵件評論是由使用 HTML 標簽的機器人和腳本發出的。如果您只是在 WordPress 評論中禁用 HTML,就可以防止大量垃圾郵件。在本教程中,我們將向您展示如何禁用 WordPress 評論中的 HTML 標簽。
本教程將僅禁用活動 HTML 標簽。所以有人仍然可以發布類似的內容:
它會顯示,但標簽不起作用。因此,如果有人使用強標記,它不會將文本加粗。此外,沒有多少垃圾郵件機器人有時間這樣做,因為這種方式占用大量時間,并且對他們沒有好處。
立即學習“前端免費學習筆記(深入)”;
您所要做的就是打開您的functions.php并添加以下代碼:
// This will occur when the comment is posted functionplc_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 functionplc_comment_display( $comment_to_display) { // Put the single quotes back in $comment_to_display= str_replace( ''', "'", $comment_to_display); return$comment_to_display;}
由
在 WordPress 中一鍵使用
如果你不想自己手動添加這段代碼,那么原作者還提供了一個插件你可以下載。只需安裝并激活Peter 的文字評論插件即可。
這種方式之所以更好,是因為它不需要你更改核心文件。如果您想編輯核心文件,那么您可以轉到wp-includes/kses.php并編輯那里的代碼。(這不是推薦的,但在這里是為了知識。(WP Codex了解更多詳細信息)