Sometimes, you might want to disable comments on your WordPress site to reduce spam or make site management easier. Here are several ways to do this.
Methods to Disable Comments:
- Using Plugins: Plugins like WPCode or Disable Comments offer different ways to turn off comments across your site or on specific post types.
- Built-In Options: WordPress has settings to stop future comments site-wide or manage them on specific pages or posts.
- Manual Method: For more control, you can edit your theme’s functions.php file.
Using a Code Snippets Plugin to Disable Comments
The WPCode plugin helps you manage code snippets, including a pre-made snippet to disable comments without directly editing code.
Steps to Use WPCode:
- Install the Plugin: Go to your WordPress dashboard, navigate to Plugins > Add New, and search for WPCode. Install and activate the plugin.
- Navigate to Code Snippets: In the left menu, find Code Snippets and look for the “Completely Disable Comments” snippet. If it’s not visible, search for it in the Library and add it to your active snippets list.
- Activate the Snippet: Toggle the Activate switch to On. This will disable comments across your entire site, including posts, pages, and custom post types. If needed, you can turn it off to re-enable comments.
Using a Specialized Plugin to Disable Comments
The Disable Comments plugin is another effective tool for managing comments.
Steps to Use Disable Comments Plugin:
- Install the Plugin: From your dashboard, go to Plugins > Add New and search for Disable Comments. Install and activate the plugin.
- Configure Settings: Navigate to Settings > Disable Comments. You have two options:
- Everywhere: Disables comments site-wide.
- On Specific Post Types: Disable comments only on selected post types like Posts, Pages, etc.
- Additional Settings: You can also remove comment-related items from various parts of your site, such as comment RSS feeds and admin bar links.
- Save Changes: Click Save Changes to apply your settings.
Using Built-In WordPress Options to Disable Comments
WordPress offers built-in settings to disable comments either globally or on a per-post basis.
Disable Future Comments:
- Go to Settings: Navigate to Settings > Discussion from your dashboard.
- Uncheck Allow Comments: Under Default post settings, uncheck the option “Allow people to submit comments on new posts”.
- Save Changes: Scroll down and click Save Changes. This stops comments on all future posts but doesn’t affect existing comments.
Disable Comments on Specific Pages or Posts:
- Edit the Post/Page: Go to Posts or Pages and click on the title of the post or page you want to edit.
- Uncheck Allow Comments: In the editor, find the Discussion settings panel and uncheck “Allow comments”.
- Update the Post/Page: Click Update or Publish to save your changes.
Disable Comments in Bulk:
- Select Multiple Posts/Pages: Navigate to the Posts or Pages menu and select the posts/pages you want to edit.
- Choose Bulk Edit: From the Bulk Actions dropdown menu, choose Edit and click Apply.
- Disable Comments: In the Bulk Edit area, find the Comments dropdown menu and select “Do not allow”.
- Update: Click Update to apply the change.
Manually Turning Off Comments
You can also disable comments by adding code to your theme’s functions.php file.
Steps to Edit Functions.php:
- Access Files: Use FTP or the File Manager in your hosting control panel to navigate to /wp-content/themes/your-child-theme/.
- Edit functions.php: Open the functions.php file and add the following code snippet:
// Disable support for comments and trackbacks in post types
function 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’, ‘disable_comments_post_types_support’);
// Close comments on the front-end
function disable_comments_status() {
return false;
}
add_filter(‘comments_open’, ‘disable_comments_status’, 20, 2);
add_filter(‘pings_open’, ‘disable_comments_status’, 20, 2);
// Hide existing comments
function disable_comments_hide_existing_comments($comments) {
$comments = array();
return $comments;
}
add_filter(‘comments_array’, ‘disable_comments_hide_existing_comments’, 10, 2);
// Remove comments page in menu
function disable_comments_admin_menu() {
remove_menu_page(‘edit-comments.php’);
}
add_action(‘admin_menu’, ‘disable_comments_admin_menu’);
// Redirect any user trying to access comments page
function disable_comments_admin_menu_redirect() {
global $pagenow;
if ($pagenow === ‘edit-comments.php’) {
wp_redirect(admin_url());
exit;
}
}
add_action(‘admin_init’, ‘disable_comments_admin_menu_redirect’);
// Remove comments metabox from dashboard
function disable_comments_dashboard() {
remove_meta_box(‘dashboard_recent_comments’, ‘dashboard’, ‘normal’);
}
add_action(‘admin_init’, ‘disable_comments_dashboard’);
- Save the File: Save your changes. Comments will now be disabled site-wide.
By following these methods, you can effectively manage and disable comments on your WordPress site.