April 23, 2024
A strong approach to globally disable comments on your WordPress site is to add this code to your functions.php
. Here’s a breakdown of how each part of your code works and its implications:
Disabling Comments Support in your function.php
function disable_comments_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('init', 'disable_comments_support', 100);
This part loops through all registered post types and removes the support for comments and trackbacks if they are supported. This change affects the WordPress backend, making it so that the option to leave comments or send trackbacks is removed from the user interface for all post types.
Closing Comments on the Front End:
function filter_comments_status() {
return false;
}
add_filter('comments_open', 'filter_comments_status', 20, 2);
This filter ensures that even if a theme or a plugin attempts to check if comments are open (via comments_open()
function), it will always return false
, indicating that comments are closed. This affects the front-end display, preventing themes from showing comment forms.
In your WordPress Settings you may also want to display Default Post Settings and check the box that USERS must be registered.
Other Points:
More Post to read
Simple Membership Plugin: Setup
January 31, 2025
Essential Tools for Checking ARIA Compliance in Web Development
October 1, 2024
Secure Your WordPress Site with a Robust .htaccess Configuration
September 3, 2024
Setting Up a New Business: Should You Choose Google Workspace or Office365?
August 29, 2024
How to Add a Domain that Works with All Google Maps Platform APIs
July 3, 2024
June 20, 2024
May 11, 2024
April 23, 2024
SQL URL Replacer – From Local to Live
April 21, 2024
Building an Accessible Accordion Component
Good Reason to Run both Cloudflare and Wordfence on Your WordPress Website
March 27, 2024
March 20, 2024
March 4, 2024
Updating Your Hosts File: Exclusive Server Preview
February 23, 2024