Why I Needed This
By default, many common WordPress themes show a “Leave a comment” section under posts, along with a “Leave a comment” link in the post meta (under the title).
For a business/product site like DevHero Digital, I don’t need comments at all — I just wanted to remove the entire comment form and the “Leave a comment” link everywhere.
Here’s the snippet I used to fix it.
What this snippet does
This PHP snippet:
- Removes the entire comment area under posts and pages in GeneratePress
- Removes the “Leave a comment” link from the post meta on blog/archive pages
- Works for all existing and future posts
- Doesn’t require editing theme files directly if you use the Code Snippets plugin
The PHP snippet (copy & paste)
Add this code via the Code Snippets plugin or in your child theme’s functions.php file:
// UNIVERSAL WORDPRESS SNIPPET
// Disable all comments on posts, pages, and custom post types
// 1) Disable support for comments and trackbacks in post types
function dhd_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', 'dhd_disable_comments_post_types_support');
// 2) Close comments on the front-end for all content
function dhd_disable_comments_status() {
return false;
}
add_filter('comments_open', 'dhd_disable_comments_status', 20, 2);
add_filter('pings_open', 'dhd_disable_comments_status', 20, 2);
// 3) Hide existing comments
function dhd_disable_comments_hide_existing($comments) {
return array();
}
add_filter('comments_array', 'dhd_disable_comments_hide_existing', 10, 2);
// 4) Remove comment-related items from the admin menu
function dhd_disable_comments_admin_menu() {
remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'dhd_disable_comments_admin_menu');
// 5) Remove comment links from the admin bar
function dhd_disable_comments_admin_bar() {
if (is_admin_bar_showing()) {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}
}
add_action('init', 'dhd_disable_comments_admin_bar');
How to add this using the Code Snippets plugin
I recommend using the free Code Snippets plugin so you don’t have to edit theme files.
- Go to Plugins → Add New and install “Code Snippets”.
- Go to Snippets → Add New.
- Set the title to:
Disable Comments Site-Wide - Paste the PHP code from above into the Code area.
- Under “Scope” or “Run snippet everywhere,” make sure it’s set to run on the front-end.
- Click Save Changes and Activate.
- Visit one of your posts or your blog page:
- The comment form should be gone
- The “Leave a comment” text/link under the title should also be gone
Optional: Turn off comments in WordPress settings too
This snippet removes the display of comments.
For a fully comment-free site, also:
- Go to Settings → Discussion
- Turn off:
- “Allow people to submit comments on new posts”
- Pingbacks/trackbacks
- Email notifications for comments
That way, you won’t get any comment spam attempts in the database either.
Summary
If you’re using common WordPress themes and don’t want comments at all, this snippet is a simple way to:
- Remove the comment form under posts/pages
- Remove the “Leave a comment” link from post meta
- Keep your site cleaner and more focused on your content or products
Feel free to copy and use this exactly like I did.