对于某些类型的WordPress站点,也许不需要在页面(page)提供评论功能,那么你可以通过下面的方法,很容易就禁用或移除WordPress页面的评论功能。

方法1:在页面编辑界面取消该页面的评论功能,如果页面编辑处未找到该功能,吧页面拉到顶部点击右上角的显示选项,把讨论 勾选。

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

 

方法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

 

相关文章:

  • 2021-10-12
  • 2021-09-16
  • 2021-07-27
  • 2021-12-03
  • 2021-11-30
  • 2021-05-26
  • 2022-01-16
  • 2021-10-22
猜你喜欢
  • 2022-12-23
  • 2022-02-05
  • 2021-08-17
  • 2022-12-23
  • 2021-07-23
  • 2021-06-06
  • 2022-12-23
相关资源
相似解决方案