彻底关闭wordpress的评论功能

October, 19th 2025 2 min read

https://www.wpbeginner.com/wp-tutorials/how-to-completely-disable-comments-in-wordpress/#completely-disable-comments

Completely Disable Comments

It is very easy to completely disable comments and remove all comments-related features from the admin panel as well as the front end of your website.

The free WPCode plugin comes with a library of pre-configured code snippets, and you can use the ‘Completely Disable Comments’ snippet to remove all traces of them from your site.

Simply install and activate WPCode, and then navigate to Code Snippets » Library in your WordPress admin panel. Here, you can search for ‘completely disable comments’ and hover your mouse over the result named the same thing.

You can then click on ‘Use Snippet.’

image 26

Now, WPCode will disable all comments-related features from your website.

If you prefer to remove all comments manually from your site, you can paste the following code into your theme’s functions.php file.

php
123456789101112131415161718192021222324252627282930313233343536373839
      add_action('admin_init', function () {
    // Redirect any user trying to access comments page
    global $pagenow;
     
    if ($pagenow === 'edit-comments.php') {
        wp_safe_redirect(admin_url());
        exit;
    }
 
    // Remove comments metabox from dashboard
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
 
    // Disable support for comments and trackbacks in post types
    foreach (get_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');
        }
    }
});
 
// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);
 
// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);
 
// Remove comments page in menu
add_action('admin_menu', function () {
    remove_menu_page('edit-comments.php');
});
 
// Remove comments links from admin bar
add_action('init', function () {
    if (is_admin_bar_showing()) {
        remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
    }
});