禁用/移除WordPress页面的评论功能

对于部分WordPress的站点,可能不想在页面(page)提供评论功能,那么可以通过下面的方法,很容易就禁用或移除WordPress页面的评论功能。

方法1禁用:将下面的代码添加到当前主题的 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’ );

方法2移除:直接打开当前主题的 page.php 文件,注销或删除类似下面的代码:

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

发表评论 0