禁用/移除WordPress頁面的評論功能


對於某些類型的WordPress站點,也許不需要在頁面(page)提供評論功能,那么你可以通過下面的方法,很容易就禁用或移除WordPress頁面的評論功能。

方法1:在頁面編輯界面取消該頁面的評論功能,如果頁面編輯處未找到該功能,吧頁面拉到頂部點擊右上角的顯示選項,把討論 勾選。

disable-or-remove-comments-of-wordpress-pages-wpdaxue_com

 

方法2:將下面的代碼添加到當前主題的 functions.php 文件,即可禁用所有頁面的評論功能:

//禁用頁面的評論功能
function disable_page_comments( $posts ) {
    if ( is_page()) {
    $posts[0]->comment_status = 'disabled';
    $posts[0]->ping_status = 'disabled';
}
return $posts;
}
add_filter( 'the_posts', 'disable_page_comments' );

 

 

方法3:直接打開當前主題的 page.php 文件,注銷或刪除類似下面的代碼:

<?php if (comments_open()) comments_template( '', true ); ?>

或者下面的函數、

comments_template

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM