WordPress評論中禁止HTML代碼顯示的方法
發(fā)布時間:2014-12-24 15:14:25 作者:佚名
我要評論

這篇文章主要為大家介紹了WordPress評論中禁止HTML代碼顯示的方法,通過增加自定義函數(shù)有效防止垃圾評論的產(chǎn)生,是非常實用的技巧,需要的朋友可以參考下
本文實例講述了WordPress評論中禁止HTML代碼顯示的方法。分享給大家供大家參考。具體分析如下:
使用WordPress的朋友會發(fā)現(xiàn)如果我們開戶了博客評論會經(jīng)??吹酱罅康睦鴱V告,帶連接了,那么我們要如何禁止用戶輸入html標簽原樣輸出,而不顯示呢,下面我來給大家介紹.
html標題無非就是由“<”、“>”組成了,我們可以反它轉換成“<”、“>”,這樣通過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( "'", ''', $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;
}
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);
// 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;
}
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);
希望本文所述對大家的WordPress建站有所幫助。
相關文章
WordPress 評論者超鏈接實現(xiàn)重定向跳轉的方法
今天我們要實現(xiàn)的就是即使收到再多的垃圾評論,這些發(fā)送評論的站點也不會被搜索引擎索引到。2011-01-30- 我們經(jīng)常會遇到nofollow屬性,特別是wordpress的評論會自動添加上external nofollow屬性。那么什么是nofollow呢?在我們不想要的時候怎么能去掉呢?2012-10-29
- wordpress回復評論文字想修改的童鞋們來看一下介紹啊2012-05-16
- 這篇文章主要為大家介紹了wordpress主題評論中添加回復的方法,可以無需通過插件來實現(xiàn)增加評論回復功能,是非常實用的技巧,需要的朋友可以參考下2014-12-20
- 這篇文章主要為大家介紹了WordPress修改評論默認頭像的方法,可實現(xiàn)定制個性化的評論頭像功能,非常具有實用價值,需要的朋友可以參考下2014-12-18
- 這篇文章主要為大家介紹了WordPress屏蔽評論中鏈接地址的方法,可通過自定義函數(shù)進行正則替換刪除鏈接,也可增加nofollow來實現(xiàn)優(yōu)化效果,需要的朋友可以參考下2014-12-18
- 這篇文章主要為大家介紹了WordPress實現(xiàn)評論提交后跳轉的方法,需要的朋友可以參考下2014-07-10
- 很多WordPress站長都飽受垃圾評論的自擾,苦不堪言。這篇文章主要為大家介紹了WordPress實現(xiàn)自動拒絕垃圾評論的方法,需要的朋友可以參考下2014-06-24
- WordPress點擊評論者鏈接是在本窗口內(nèi)打開,用戶體驗不是特別好,介紹一下wordpress評論者鏈接在新窗口中打開的方法,解決方法如下2014-01-26
wordpress教程防wordpress廣告的方法 評論中包含過多鏈接不可提交
本文介紹了wordpress評論防廣告的方法,代碼寫在主題目錄下functions.php,全英文、超鏈接>3個均不能pass spam check,超鏈接就簡單使用http作為特征碼判斷,可以根據(jù)實際2014-01-26