WordPress部落格評論禁止HTML代碼顯示

來源:互聯網
上載者:User

html標題無非就是由“<”、“>”組成了,我們可以反它轉換成“&lt;”、“&gt;”,這樣通過HTML編譯,自動變成了“<”、“>” 我們也可以直接替換掉了

找到一國外人的代碼,搞定了。不過不一定他是原作者。

在functions.php的PHP代碼裡加入:

 代碼如下 複製代碼

//禁用wordpress評論html代碼
// 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( "'", '&apos;', $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( '&apos;', "'", $comment_to_display );
 return $comment_to_display;
}
add_filter( 'preprocess_comment', 'plc_comment_post', '', 1);
add_filter( 'comment_text', 'plc_comment_display', '', 1);
add_filter( 'comment_text_rss', 'plc_comment_display', '', 1);
add_filter( 'comment_excerpt', 'plc_comment_display', '', 1);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.