How to completely disable comments in WordPress using functions.php
WordPress
WordPress is a flexible and open source CMS but it does have a few issues, especially with it’s comments system attracting spam and malware! If your website doesn’t rely on blogging or interactions from users on the WWW, softdata recommends you to disable comments in WordPress via adding a simple script within your functions.php file.
See below 🙂
How to disable comments in WordPress
Simply copy and paste the below script into your functions.php file in your WordPress theme folder.
function df_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’, ‘df_disable_comments_post_types_support’);
// Then close any comments open comments on the front-end just in case
function df_disable_comments_status() {
return false;
}
add_filter(‘comments_open’, ‘df_disable_comments_status’, 20, 2);
add_filter(‘pings_open’, ‘df_disable_comments_status’, 20, 2);
// Finally, hide any existing comments that are on the site.
function df_disable_comments_hide_existing_comments($comments) {
$comments = array();
return $comments;
}
add_filter(‘comments_array’, ‘df_disable_comments_hide_existing_comments’, 10, 2);
Why should comments in WordPress be disabled?
Comments in WordPress should be disabled for a number of reasons. First and foremost, they can be a source of confusion and frustration for users. Comments are essentially message boards where users can post comments on other users’ posts. This can lead to confusion and frustration for users, who might not know how to properly use comments or who might not understand what others are saying.
Comments also consume server resources. Every time a comment is made, WordPress must load the comment content from the server. This can slow down the loading of posts and can even cause the site to crash. Finally, comments can be a breeding ground for spam. By allowing comments, WordPress encourages users to post inflammatory, spammy, and offensive content. This can lead to increased spam on the site, decreased user satisfaction, and eventually, site abandonment.
Disabling comments can help to improve user satisfaction, speed up page loading, and reduce spam on the site.
Digital Marketing Agency in Gloucester and Cheltenham
Softdata is a leading digital agency and AI Services provider based in Gloucester and Cheltenham.About us: Softdata is a premier digital software agency and digital marketing provider, based in Gloucester and Cheltenham. We offer a range of digital services including web design, bespoke software development, SEO, Paid advertising, conversion rate optimisation, web hosting, and AI consultancy services. Our team is dedicated to providing the best solutions tailored to the unique needs of our clients.
If you would like to discuss your needs with a Digital Specialist, we offer a Free Initial Consultation without cost or commitment. Meetings can be held at our offices, via video conference, or by telephone. Our telephone number is 01452 502 508.
Softdata is located at: Softdata Internet Limited, 80 Westgate Street, Gloucester, GL1 2NZ.