When I started using WordPress, I welcomed comments and I thought that all sites kinda did the same thing.
I remember getting comments from real site users and also comments from bots who were trying to get a backlink from my site.
I didn’t know how to disable comments so I dealt with them for quite a while.
Table of Contents
How to Disable Comments from My Blogs
Then I figured out that I could get rid of them and I did based on two main reasons:
- Interaction is rarely taking place on the comment sections of blogs.
- If you have a comment section, your site will see additional requests.
I had disabled comments using different plugins, Perfmatters being the most common one to accomplish that.
Then I created a mu-plugin to deal with that. Feel free to use it if you are like me and understand we don’t need to install a plugin to change every tiny little thing in WordPress
<?php
/*
Plugin Name: Comments Remover
Plugin URI: https://ticolibre.com
Description: Remove Comments from from your WordPress site.
Version: 1.0
Author: TicoLibre
Author URI: https://ticolibre.com
*/
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_safe_redirect(admin_url());
exit;
}
// Remove comments metabox from dashboard
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
// 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');
}
}
});
// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);
// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);
// Remove comments page in menu
add_action('admin_menu', function () {
remove_menu_page('edit-comments.php');
});
// Remove comments links from admin bar
add_action('init', function () {
if (is_admin_bar_showing()) {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}
});
Enabling Comments Again
Then the Helpful Content Update and made me wonder if disabling comments entirely from my website was a a bad idea.
If we truly think that we are an authority on the topic we write about, we should probably welcome questions and answer them.
Also I think I know enough to prevent most common spam problem related to WordPress comments.
Since I have spent some good amount of time optimizing my site:
- You can delay the script added by the comment section.
- You can load the comment section style in the footer.
If you get lucky enough and your content inspire a lively conversation, time spent on your site and ad viewability rate will improve
Removing the Website URL Field
If you want to do that, you should enable comments again but this time, you shouldn’t let commenters add their author link
You don’t need a plugin to remove the website URL field from your form, this is the code snippet that will do the trick
<?php
/*
Plugin Name: Comment Author Link Remover
Plugin URI: https://ticolibre.com
Description: Remove Website URL Field From WordPress Comment Form
Version: 1.0
Author: TicoLibre
Author URI: https://ticolibre.com
*/
add_filter('comment_form_field_url', '__return_false');
You will find other code snippets that will prevent WordPress from saving the website URL but won’t remove the field from the comment box.
The code shared here will remove the website URL so spammers and users trying to get a backlink from your site don’t get one.
I checked the source code and I didn’t find a trace of the website URL field when the previous mu-plugin is implemented.
How to Stop Making Links in Comments Clickable
Now that you have stopped users and bots from adding the website URL, you should also consider stopping WordPress from making links added as text in comments clickable
You can use this simple filter to do so:
remove_filter('comment_text', 'make_clickable', 9);
In case you don’t want to create an additional mu-plugin for that, you can add that code snippet to the existing mu-plugin:
<?php
/*
Plugin Name: Comment Author Link Remover
Plugin URI: https://ticolibre.com
Description: Remove Website URL Field From WordPress Comment Form
Version: 1.0
Author: TicoLibre
Author URI: https://ticolibre.com
*/
add_filter('comment_form_field_url', '__return_false');
remove_filter('comment_text', 'make_clickable', 9);
Customize Comments Section using CSS
If the forms work as you want to, you might want to know how to change the look of it
The following CSS snippets are examples so feel free to change and add more to it as you see fit.
In case you want to change the submit button, this is the CSS snippet for that:
#submit.submit {
background-color: #FF1849;
color: white;
border-radius: 12px;
}