Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Turn off comments everywhere

Closes comments and pingbacks on every post and page, hides existing comments, and removes Comments from the admin menu, the admin bar and the dashboard. WooCommerce product reviews keep working.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Tested with WordPress 7.1
PHP
<?php

// Post types that keep their comments (WooCommerce reviews are comments).
$keep = array( 'product' );

add_filter( 'comments_open', static fn( $open, $post_id ) => in_array( get_post_type( $post_id ), $keep, true ) ? $open : false, 20, 2 );
add_filter( 'pings_open', static fn( $open, $post_id ) => in_array( get_post_type( $post_id ), $keep, true ) ? $open : false, 20, 2 );
add_filter( 'comments_array', static fn( $comments, $post_id ) => in_array( get_post_type( $post_id ), $keep, true ) ? $comments : array(), 20, 2 );
add_filter( 'feed_links_show_comments_feed', '__return_false' );

add_action(
	'init',
	static function () use ( $keep ) {
		foreach ( get_post_types() as $post_type ) {
			if ( ! in_array( $post_type, $keep, true ) && post_type_supports( $post_type, 'comments' ) ) {
				remove_post_type_support( $post_type, 'comments' );
				remove_post_type_support( $post_type, 'trackbacks' );
			}
		}
	},
	100
);

add_action(
	'admin_menu',
	static function () {
		remove_menu_page( 'edit-comments.php' );
		remove_submenu_page( 'options-general.php', 'options-discussion.php' );
	},
	100
);

add_action(
	'admin_init',
	static function () {
		global $pagenow;
		if ( in_array( $pagenow, array( 'edit-comments.php', 'options-discussion.php' ), true ) ) {
			wp_safe_redirect( admin_url() );
			exit;
		}
	}
);

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

add_action(
	'admin_bar_menu',
	static function ( $admin_bar ) {
		$admin_bar->remove_node( 'comments' );
	},
	100
);

In these packs

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.