Most business websites don’t need comments. A service page or a portfolio has nothing to discuss, and an open comment form mostly attracts spam bots.
WordPress lets you turn comments off, but only one post at a time, and the Comments menu stays in the dashboard. This snippet switches them off everywhere at once.
What the snippet does
- Closes comments and pingbacks on every post, page and custom post type
- Hides comments that are already published
- Removes the Comments menu, the admin bar icon and the dashboard widget
- Blocks the Comments screen if someone opens it directly
Your old comments are not deleted. They stay in the database, so you can bring them back by removing the snippet.
The code
/**
* Close comments and pingbacks on the front end
*/
add_filter( 'comments_open', '__return_false', 20 );
add_filter( 'pings_open', '__return_false', 20 );
/**
* Hide comments that are already published
*/
add_filter( 'comments_array', '__return_empty_array', 10 );
/**
* Remove comment support from every post type
* and send the Comments screen back to the dashboard
*/
add_action( 'admin_init', function () {
global $pagenow;
if ( 'edit-comments.php' === $pagenow ) {
wp_safe_redirect( admin_url() );
exit;
}
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
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' );
}
}
} );
/**
* Remove the Comments menu and the admin bar icon
*/
add_action( 'admin_menu', function () {
remove_menu_page( 'edit-comments.php' );
} );
add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {
$wp_admin_bar->remove_node( 'comments' );
}, 999 );
How it works
comments_open and pings_open are the checks WordPress runs before it shows a comment form or accepts a pingback. Returning false closes both on every post, old and new. Bots that post straight to wp-comments-post.php get rejected too, because that file runs the same check.
comments_array holds the comments a post is about to show. Returning an empty array hides them without touching the database.
The admin_init part cleans up the dashboard: it removes the comment box from the post editor, the Recent Comments widget, and redirects anyone who opens the Comments screen.
How to add the code
- Open your child theme’s
functions.php, or create a new PHP snippet in a plugin such as Code Snippets. Never edit a parent theme: an update will wipe your changes. - Paste the code and save.
- Open any post on the front end. The comment form and old comments should be gone.
- Check the dashboard. The Comments menu should no longer be in the sidebar.
Good to know
- Your theme may still show a “Comments are closed” line. That text comes from the theme’s template, not from WordPress. Hide it with CSS, or remove it in a child theme.
- Comment count bubbles in some themes read the number from the database. They can still show old numbers until you delete those comments in Comments → All Comments, before you add the snippet.
- Want comments on the blog only? Don’t use this snippet. Turn off comments per post instead, under Settings → Discussion for new posts, and with Bulk Edit → Comments → Do not allow for existing ones.
One snippet, and your site is free of comment spam.

