Although wordpress has got better over the years with being able to combat spam issues, through DNS protection, various CAPTCHA, honeypot methods and the impressive Akismet service developed by AUTOMATTIC (the wordpress foundation).  I always just find that sites run better, are simpler to manage and less stressful to the customer by removing the whole concept of comments out of the software.

The following code is perfect for just stripping it out of the wordpress administration area and from theme files.

  1. // Remove comments from Wordpress completely
  2. // Disable support for comments and trackbacks in post types
  3.  
  4. function df_disable_comments_post_types_support() {
  5. $post_types = get_post_types();
  6. foreach ($post_types as $post_type) {
  7. if(post_type_supports($post_type, 'comments')) {
  8. remove_post_type_support($post_type, 'comments');
  9. remove_post_type_support($post_type, 'trackbacks');
  10. }
  11. }
  12. }
  13. add_action('admin_init', 'df_disable_comments_post_types_support');
  14. // remove comments on front end
  15. function df_disable_comments_status() {
  16. return false;
  17. }
  18. add_filter('comments_open', 'df_disable_comments_status', 20, 2);
  19. add_filter('pings_open', 'df_disable_comments_status', 20, 2);
  20. // remove existing comments
  21. function df_disable_comments_hide_existing_comments($comments) {
  22. $comments = array();
  23. return $comments;
  24. }
  25. add_filter('comments_array', 'df_disable_comments_hide_existing_comments', 10, 2);
  26. // remove comments page in admin menu
  27. function df_disable_comments_admin_menu() {
  28. remove_menu_page('edit-comments.php');
  29. }
  30. add_action('admin_menu', 'df_disable_comments_admin_menu');
  31. // redirect user from accessing the comments page
  32. function df_disable_comments_admin_menu_redirect() {
  33. global $pagenow;
  34. if ($pagenow === 'edit-comments.php') {
  35. wp_redirect(admin_url()); exit;
  36. }
  37. }
  38. add_action('admin_init', 'df_disable_comments_admin_menu_redirect');
  39. // remove comments meta from admin dashboard
  40. function df_disable_comments_dashboard() {
  41. remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
  42. }
  43. add_action('admin_init', 'df_disable_comments_dashboard');
  44. // remove comments from top admin menu bar
  45. function my_admin_bar_render() {
  46.     global $wp_admin_bar;
  47.     $wp_admin_bar->remove_menu('comments');
  48. }
  49. add_action( 'wp_before_admin_bar_render', 'my_admin_bar_render' );

Want the comments functionality back? – Remove the code and it will be restored.

Leave a Reply

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