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

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

方法1:在页面编辑界面取消该页面的评论功能

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

方法2:将下面的代码添加到当前主题的 functions.php 文件,即可禁用所有页面的评论功能:

1
2
3
4
5
6
7
8
9
//禁用页面的评论功能
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' );

//禁用页面的评论功能
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 文件,注销或删除类似下面的代码:

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

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

本人擅长Ai、Fw、Fl、Br、Ae、Pr、Id、Ps等软件的安装与卸载,精通CSS、JavaScript、PHP、ASP、C、C++、C#、Java、Ruby、Perl、Lisp、Python、Objective-C、ActionScript、Pascal等单词的拼写,熟悉Windows、Linux、OS X、Android、iOS、WP8等系统的开关机。

通过下面的方式来联系我们:

电邮:138762189@qq.com

联系QQ:点击这里给我发消息

官方站:www.tadke.com

※ ※ 联系请加我的企鹅号 ※※

※ ※技术支持请微信联系站长 ※※

Copyright © 2023 Tadke.com. 琼ICP备20000547号