隐藏或删除wordpress页面中的注释框

时间:2013-03-29 11:47:25

标签: wordpress-plugin wordpress

我正在开发一个插件,一切都很顺利,但是有一个问题 如何隐藏或删除评论框。我失去了很多时间,但无法开发出正确的剧本。我目前的剧本就是这个 add_filter( 'comments_template', 'remove_comments_template_on_pages', 11 );
function remove_comments_template_on_pages( $file ) {
     if ( is_page() )
comments_template('', true);
}

我不知道如何开发这个脚本。任何帮助都可以让我完成我的插件。

1 个答案:

答案 0 :(得分:0)

将以下代码添加到 functions.php 文件中。

add_action('init', 'remove_page_feature');

function remove_page_feature() {
    remove_post_type_support( 'page', 'comments' );
}

现在在执行评论模板之前提供检查,如下所示:

if ( post_type_supports( 'page', 'comments' );  )
    comments_template('', true);
}

注意:使用上述代码会禁用网页上的评论