HomeMethod

Knowledge

Web VitalsTechniquesSnippetsAnswersImpactsBottlenecks

Disable comments site-wide

  • WordPress

For business sites, portfolios, and landing pages, the comment system is pure noise — it adds admin UI clutter, database queries, and an attack surface for spam. WordPress doesn’t have a single switch to turn it off, so you need to close comments at multiple levels.

disable-comments.php
<?php
/**
 * Disable Comments Site-Wide
 *
 * Completely removes the commenting system from WordPress — closes existing
 * comments, removes the admin menu, hides the dashboard widget, strips the
 * admin bar link, and disables comment support on all post types. Useful for
 * business sites, portfolios, and landing pages where comments are noise.
 *
 * Usage: Add to functions.php.
 *
 * @category wordpress
 * @language php

 *
 * @author Adame Dahmani https://adame.io
 * @support Support my family project: https://adame.io/fundraiser
 */
add_action( 'admin_init', function () {
    $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_filter( 'comments_open', '__return_false', 20, 2 );
add_filter( 'pings_open', '__return_false', 20, 2 );
add_filter( 'comments_array', '__return_empty_array', 10, 2 );

add_action( 'admin_menu', function () {
    remove_menu_page( 'edit-comments.php' );
} );

add_action( 'admin_init', function () {
    remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
} );

add_action( 'wp_before_admin_bar_render', function () {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu( 'comments' );
} );

This removes comment support from all post types, closes comments on existing posts, removes the admin menu item, hides the dashboard widget, and strips the comment link from the admin bar.

Support our family now