How to Completely Disable Comments

WordPress has a builtin comments system that works pretty well. However in some cases, especially if you use WordPress as a CMS, not a blogging platform, you may find it dispensable. For some of us turning off comments in Discussion settings is enough, but what if you want to disable access to the comments menu in admin, remove comments from admin bar and post types columns or hide existing comments at the front-end of your site? It’s not that easy, but this piece of code might help.

// Disable support for comments and trackbacks in post types
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');

// Close comments on the front-end
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);

// Hide existing comments
function df_disable_comments_hide_existing_comments($comments) {
	$comments = array();
	return $comments;
}
add_filter('comments_array', 'df_disable_comments_hide_existing_comments', 10, 2);

// Remove comments page in menu
function df_disable_comments_admin_menu() {
	remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'df_disable_comments_admin_menu');

// Redirect any user trying to access comments page
function df_disable_comments_admin_menu_redirect() {
	global $pagenow;
	if ($pagenow === 'edit-comments.php') {
		wp_redirect(admin_url()); exit;
	}
}
add_action('admin_init', 'df_disable_comments_admin_menu_redirect');

// Remove comments metabox from dashboard
function df_disable_comments_dashboard() {
	remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
}
add_action('admin_init', 'df_disable_comments_dashboard');

// Remove comments links from admin bar
function df_disable_comments_admin_bar() {
	if (is_admin_bar_showing()) {
		remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
	}
}
add_action('init', 'df_disable_comments_admin_bar');

After adding this to your functions.php file in theme, comments in WordPress will be gone.

Leave a Reply

Your email address will not be published. Required fields are marked *

40 comments on "How to Completely Disable Comments"

  1. Keep working ,impressive job!

  2. Thank so much for this … I would rather use code than a plugin… Plugins BAD!!!!

  3. thank you a lot

  4. Where exactly is this code inserted in the FUNCTIONS.PHP file? I am new to WordPress.

    Thank you.

    • You can paste this anywhere.

  5. One Addition and an Amendment for this.

    1. To remove the comments from the admin bar:
    // Remove comments link in admin bar
    function df_remove_comments_admin_bar_links() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu(‘comments’);
    }
    add_action(‘wp_before_admin_bar_render’, ‘df_remove_comments_admin_bar_links’);

    2. To disable the discussion page and redirect it:
    // Remove comments page in menu
    function df_disable_comments_admin_menu() {
    remove_menu_page(‘edit-comments.php’);
    remove_submenu_page(‘options-general.php’, ‘options-discussion.php’);
    }
    add_action(‘admin_menu’, ‘df_disable_comments_admin_menu’);

    // Redirect any user trying to access comments page
    function df_disable_comments_admin_menu_redirect() {
    global $pagenow;
    if ($pagenow === ‘edit-comments.php’ || $pagenow === ‘options-discussion.php’) {
    wp_redirect(admin_url()); exit;
    }
    }
    add_action(‘admin_init’, ‘df_disable_comments_admin_menu_redirect’);

    Hope that helps someone.

    • Thanks Garrett. It’s a nice improvement.

    • Another Addition, If you want to remove the Metaboxes on all post types, such as the Reviews metabox on Products add the following.

      // Remove meta boxes for comments, reviews and trackbacks in post types
      function ljlee_remove_comments_metabox_post_types() {
      $post_types = get_post_types();
      foreach ($post_types as $post_type) {
      remove_meta_box(‘commentsdiv’, $post_type, ‘normal’);
      remove_meta_box(‘commentsstatusdiv’, $post_type, ‘normal’);
      remove_meta_box(‘trackbacksdiv’, $post_type, ‘normal’);
      }
      }
      add_action(‘add_meta_boxes’, ‘ljlee_remove_comments_metabox_post_types’, 99);

  6. Thanks, works great!
    With one modification – in order to remove the admin bar item, i had to use ‘add_admin_bar_menus’ hook, instead of ‘init’. I’m using WordPress 4.0, haven’t tested for previous versions…
    Cheers ;)

  7. Very useful, worked first time and thanks.

  8. Thanks. That solved my problem. :)

  9. Another suggestion would be to just kill the wordpress comment function.
    I found that to be the best move.

  10. Hi, sorry i am a noob. I added this to the function.php (right at the end) and got blank page, i can’t even log in now too.
    The theme is twelve eleven.

    • No problem. You had probably overriden a part of code, made a typo, pasted this not inside the php code or something similar.

      • Erm thanks, I copied everything so probably it’s not typo but is there anything I can do to rectify?

      • It’s not the problem with the code but the place you pasted this. This is a PHP code, you can’t paste it just anywhere into the file.

        You should try to replace the modified functions.php file with the default one for Twenty Eleven (via FTP connection for example).

  11. This worked great- thanks!

  12. Can i revert the changes of this by simply removing those lines?
    I just wanna see if disqus works after doing that

    • Absolutely. You just remove or comment the code and eveything works as it did before.

  13. Perfect, no problem thanks.

  14. GR8 Work :-))

  15. A W E S O M E … Automagically i got no comments now, Thanks a lot!

  16. Very Helpfull !
    I removed the “Discussion” sub-menu page from the “Settings” aswell by adding :
    remove_submenu_page( ‘options-general.php’, ‘options-discussion.php’ );
    in df_disable_comments_admin_menu() { … }

  17. Just implemented these functions on one of my client websites.

    One small issue — I’m using WP 3.7.1, and the Comments button is still visible in the Admin Toolbar (across top of Dashboard), even though I included the function, df_disable_comments_admin_bar

    Is there something else I can do to disable that button? Right now, if the button is clicked, it just forwards to the main dashboard screen, so no real problem, but I’d prefer to remove the button if possible to prevent user confusion.

    Otherwise, code seems to be working great, thanks a bunch!

    • Is your client site a multisite install?

      • No, just a single site. I do perhaps have a non-standard directory location for the install, if that’s what you’re getting at. (I am not a programmer, so there may be some aspects of this that escape me.)

        In any case, the manual code also caused one of my Admin panel menu items (which appears below ‘Comments’) to become unavailable. I suspect this was due to a buggy plugin (not your manual code), but unfortunately we do need to use that particular plugin. So ultimately I decided to use a plug-in for disabling comments, rather than the manual code. Someday when I’m more adept with php, I’ll try to eliminate the plugin and use the manual method, so I’ve bookmarked this page.

        I’m glad I discovered your website during this process, as it made me aware of your plugins, which I plan to investigate. :-)

        Thanks!

    • This is how you can do it:

      function mytheme_hide_admin_comments_link() {
      global $wp_admin_bar;
      $wp_admin_bar->remove_menu( ‘comments’ );
      }
      add_action(‘wp_before_admin_bar_render’, ‘mytheme_hide_admin_comments_link’);

  18. Great help!

    Is there anyway to remove the text: “Comments are closed.” I see this at the bottom of the posts

    • Nick, this is displayed in your theme, usually in comments.php file. Find and remove the line of code that echoes that.

  19. I think the syntax error comes from your parent theme’s functions.php

  20. Hi
    I have made a child theme for Coraline http://wordpress.org/themes/coraline and a new functions.php in my child them, but I got this error

    Parse error: syntax error, unexpected T_FUNCTION in /home/www/brunbi.vemmelev-webdesign.dk/wp-content/themes/coraline-child/functions.php on line 19

    My functions.php looks like this

    Can you tell me what is wrong

    Regards, Carl

    • Carl, I don’t see your code but this is just a syntax error in your code.

      • Please don’t paste all of your code here. Just use any php editing software – it should show you where the error is.

  21. Thanks a lot, just what I was looking for!

  22. After you’ve used this script will your site allow you to use an external comments app like Disqus? If how coul it be used in combination with Disqus?

    • Hard to say Mike. I think it should allow you to use Disqus as this code is intended to remove builtin comments, while Disqus is an outsourced comments system.

      • Thanks Bartosz. Appreciated.

  23. Great solution, thanks

  24. Sick man! That’s what I was looking.

    Thanks a lot!

  25. wow. what a pile of solutions.
    thanks