WordPress 禁用页面的评论功能
WordPress 站点页面有时可能不需要评论功能,如果你也有此需求,以下三种方法可以任选一个来禁用评论功能。
1、编辑当前主题的 page.php ,注释或删除以下类似代码。
<?php comments_template( '', true ); ?>
2、在页面编辑窗口,取消页面的“允许评论”选中状态。
3、添加以下代码到当前主题的 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' );
『 转载请注明来源及链接 』