Disable Comments Sitewide (and Close on Old Posts) in WordPress
Comments can sometimes attract spam, require moderation, or simply no longer fit the purpose of your WordPress site. Disabling comments sitewide and closing comments on older posts is a straightforward way to maintain control over user interaction and reduce maintenance. This guide shows you how to quickly disable comments across your entire WordPress site and automatically close comments on posts older than a specified number of days.
Quick Fix: Disable Comments Sitewide
- Go to your WordPress admin dashboard.
- Navigate to Settings > Discussion.
- Uncheck Allow people to submit comments on new posts.
- Save changes.
- To disable comments on existing posts, use the bulk edit feature or apply a code snippet (see below).
- To close comments on old posts automatically, add a custom function to your theme’s
functions.php
file or a site-specific plugin.
Why This Happens
By default, WordPress allows comments on new posts unless disabled manually. Existing posts retain their comment status unless changed individually or programmatically. Older posts may continue to accept comments indefinitely, which can lead to spam or outdated discussions. Disabling comments sitewide and closing them on older posts helps maintain site cleanliness and reduces moderation workload.
Step-by-Step: Disable Comments Sitewide and Close on Old Posts
1. Disable Comments on New Posts via Settings
This prevents comments on all future posts.
Dashboard > Settings > Discussion
- Uncheck "Allow people to submit comments on new posts"
- Save Changes
2. Disable Comments on Existing Posts in Bulk
Use WordPress bulk edit to disable comments on existing posts:
- Go to Posts > All Posts.
- Select all posts (increase posts per page if needed).
- Choose Edit from the Bulk Actions dropdown and click Apply.
- Set Comments to Do not allow.
- Click Update.
3. Programmatically Close Comments on Old Posts
Add the following code snippet to your theme’s functions.php
file or a site-specific plugin. This will automatically close comments on posts older than 30 days (adjustable):
function close_comments_on_old_posts( $open, $post_id ) {
$days = 30; // Number of days after which comments close
$post = get_post( $post_id );
if ( 'post' === $post->post_type ) {
$post_age = ( time() - strtotime( $post->post_date ) ) / DAY_IN_SECONDS;
if ( $post_age > $days ) {
return false; // Close comments
}
}
return $open;
}
add_filter( 'comments_open', 'close_comments_on_old_posts', 10, 2 );
4. Disable Comments on Other Content Types
To disable comments on pages or custom post types, extend the bulk edit or use this snippet to disable comments sitewide:
function disable_comments_everywhere() {
// 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' );
}
}
}
add_action( 'admin_init', 'disable_comments_everywhere' );
// Close comments on front-end
function filter_comments_open( $open, $post_id ) {
return false;
}
add_filter( 'comments_open', 'filter_comments_open', 20, 2 );
add_filter( 'pings_open', 'filter_comments_open', 20, 2 );
Common Pitfalls
- Theme or plugin overrides: Some themes or plugins may override comment settings. Check for theme options or plugin settings that enable comments independently.
- Cached pages: If you use caching plugins or server caching, changes may not appear immediately. Clear caches after applying changes.
- Bulk edit limits: Bulk editing posts is limited by the number of posts shown per page. Increase the number of posts per page or repeat the process for all pages.
- Child theme usage: When adding code snippets, use a child theme or a site-specific plugin to avoid losing changes after theme updates.
Works on
This method works on all standard WordPress setups regardless of the web server:
- Apache
- Nginx
- LiteSpeed
- cPanel and Plesk hosting environments
- Multisite WordPress installations (note: bulk edit applies per site)
FAQ
- Q: Will disabling comments delete existing comments?
- No, disabling comments only prevents new comments. Existing comments remain visible unless you delete them manually.
- Q: Can I disable comments only on pages and not posts?
- Yes. You can selectively disable comments by modifying the code snippet to target only the ‘page’ post type or use bulk edit on pages only.
- Q: How do I re-enable comments later?
- Simply reverse the changes: enable comments in Settings > Discussion, remove or comment out the code snippets, and bulk edit posts/pages to allow comments again.
- Q: Does this method affect pingbacks and trackbacks?
- The provided code disables both comments and pingbacks/trackbacks. You can adjust the filters if you want to keep pingbacks enabled.
- Q: Is there a plugin alternative?
- Yes, plugins like “Disable Comments” offer UI-based options to disable comments sitewide or selectively. However, manual code snippets provide more control and avoid plugin bloat.