I often use WordPress as a full-fledged CMS rather than a straight blogging platform, and more often than not want to completely remove comment functionality – both on the front and back end of my WordPress theme. Comment activity, options, and related code can be found in a number of places throughout the admin pages, and this post will cover the functions necessary to hide and disable these in WordPress 4.4.
All of these snippets should be added to your
functions.php file (or an include).
Remove post type support
First use the WordPress function
remove_post_type_support attached to the
init action hook to remove the comment count column that appears on the main Posts or Pages edit screens.
Remove admin menu item
remove_menu_page function will remove the Comments tab found on the left sidebar menu in the WordPress admin.
Remove meta boxes
remove_meta_box is included to hide the comments meta box – along with the discussion meta box – from single Post and Page edit screens.
Clean up admin Dashboard
There are still several references to comments on the main Dashboard admin page found in the At a Glance and Activity meta boxes, along with a comment count in the admin bar. The
admin_head action hook can be used to quickly add CSS to the head of our admin pages and set all of these elements to
Disable comment reply script
Some themes include the function call
comment-reply.min.js. Search your theme directory for
comment-reply and remove that line.
Modify template files
If you’re building a custom theme from the ground up, then no need to worry about this. In the case you’re starting from a theme boilerplate or existing code you will want to remove the comment template from the single post view. Look for a function called
single.php and remove it.
I also like to delete the file
comments.php from my theme directory to keep things as clean as possible.
Clean up the database
If for some reason you already had comments on your blog you may want to take the extra step of cleaning them out of your database, assuming they’re no longer needed. You can safely remove all rows from the
WordPress plugin solution
You could also use this plugin. I haven’t personally tested it, but based solely on the reviews and active installs I would say it’s reputable. I’ll save the discussion of what should be a plugin vs. what to include as theme functionality for another day.