Answers:
这是上述所有答案的列表,并删除了管理栏链接。只需将其添加到主题功能文件中或使其成为插件即可。我将其标记为社区Wiki,因为每个人的回答都是正确的,只是没有人将其全部加在一起。
<?php
// Removes from admin menu
add_action( 'admin_menu', 'my_remove_admin_menus' );
function my_remove_admin_menus() {
remove_menu_page( 'edit-comments.php' );
}
// Removes from post and pages
add_action('init', 'remove_comment_support', 100);
function remove_comment_support() {
remove_post_type_support( 'post', 'comments' );
remove_post_type_support( 'page', 'comments' );
}
// Removes from admin bar
function mytheme_admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('comments');
}
add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );
?>
这应该删除对您网站上评论的支持:
add_action('admin_menu', 'remove_comment_support');
function remove_comment_support() {
remove_post_type_support( 'post', 'comments' );
remove_post_type_support( 'page', 'comments' );
}
我不知道它是否会隐藏管理部分中的所有评论。仪表板上的“ Right Now”框大部分是硬编码的,因此您必须隐藏该框或做些黑客手段来过滤掉有关“ Comments”的注释。但是它应该删除我能想到的其他任何地方的“评论”文本。
这本身不会从标记中删除它,但是您可以通过将以下行添加到主题的CSS中来轻松隐藏WP 3.1管理栏链接(无论是在视觉上还是在屏幕阅读器上):
li#wp-admin-bar-comments { display: none; visibility: hidden; }
current_user_can
功能,例如:if (!current_user_can('level_10'))
仅针对非管理员用户。
有一个现成的解决方案可以做到这一点。这是FrankBültge的插件
文件:http: //wpengineer.com/2230/removing-comments-absolutely-wordpress/
插件下载:https: //github.com/bueltge/Remove-Comments-Absolutely
只需安装,就可以了。没有配置。
与WP 3.5兼容
// Disable support for comments and trackbacks in post types
function df_disable_comments_post_types_support() {
$post_types = get_post_types();
foreach ($post_types as $post_type) {
if(post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
}
}
add_action('admin_init', 'df_disable_comments_post_types_support');
// Close comments on the front-end
function df_disable_comments_status() {
return false;
}
add_filter('comments_open', 'df_disable_comments_status', 20, 2);
add_filter('pings_open', 'df_disable_comments_status', 20, 2);
// Hide existing comments
function df_disable_comments_hide_existing_comments($comments) {
$comments = array();
return $comments;
}
add_filter('comments_array', 'df_disable_comments_hide_existing_comments', 10, 2);
// Remove comments page in menu
function df_disable_comments_admin_menu() {
remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'df_disable_comments_admin_menu');
// Redirect any user trying to access comments page
function df_disable_comments_admin_menu_redirect() {
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url()); exit;
}
}
add_action('admin_init', 'df_disable_comments_admin_menu_redirect');
// Remove comments metabox from dashboard
function df_disable_comments_dashboard() {
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
}
add_action('admin_init', 'df_disable_comments_dashboard');
// Remove comments links from admin bar
function df_disable_comments_admin_bar() {
if (is_admin_bar_showing()) {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}
}
add_action('init', 'df_disable_comments_admin_bar');