默認(rèn)情況下,wordpress 允許在評(píng)論中包含某些 html 標(biāo)簽,例如 等。如果您發(fā)現(xiàn)很多垃圾評(píng)論也包含這些標(biāo)簽。大多數(shù)垃圾郵件評(píng)論是由使用 HTML 標(biāo)簽的機(jī)器人和腳本發(fā)出的。如果您只是在 WordPress 評(píng)論中禁用 HTML,就可以防止大量垃圾郵件。在本教程中,我們將向您展示如何禁用 WordPress 評(píng)論中的 HTML 標(biāo)簽。
本教程將僅禁用活動(dòng) HTML 標(biāo)簽。所以有人仍然可以發(fā)布類(lèi)似的內(nèi)容:
它會(huì)顯示,但標(biāo)簽不起作用。因此,如果有人使用強(qiáng)標(biāo)記,它不會(huì)將文本加粗。此外,沒(méi)有多少垃圾郵件機(jī)器人有時(shí)間這樣做,因?yàn)檫@種方式占用大量時(shí)間,并且對(duì)他們沒(méi)有好處。
立即學(xué)習(xí)“前端免費(fèi)學(xué)習(xí)筆記(深入)”;
您所要做的就是打開(kāi)您的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 中一鍵使用
如果你不想自己手動(dòng)添加這段代碼,那么原作者還提供了一個(gè)插件你可以下載。只需安裝并激活Peter 的文字評(píng)論插件即可。
這種方式之所以更好,是因?yàn)樗恍枰愀暮诵奈募H绻刖庉嫼诵奈募敲茨梢赞D(zhuǎn)到wp-includes/kses.php并編輯那里的代碼。(這不是推薦的,但在這里是為了知識(shí)。(WP Codex了解更多詳細(xì)信息)