Skip to content

Instantly share code, notes, and snippets.

@treetrum
Last active October 9, 2017 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save treetrum/35b78bacd174007aa96f73242b3de080 to your computer and use it in GitHub Desktop.
Save treetrum/35b78bacd174007aa96f73242b3de080 to your computer and use it in GitHub Desktop.
Remove comments on WordPress without a plugin
<?php
add_action('init', 'remove_comment_support', 100);
function remove_comment_support() {
// Remove post type support for each post type
foreach (get_post_types() as $post_type) {
if (post_type_supports( $post_type, 'comments' )) {
// Don't remove comment support for shop orders
if ($post_type !== 'shop_order') {
remove_post_type_support( 'page', 'comments' );
}
}
}
// Uncomment the following to force hiding comment meta boxes
// remove_meta_box( 'commentsdiv', 'post', 'normal' );
}
// Hide edit screen in WP backend
add_action( 'admin_menu', 'remove_comments_page' );
function remove_comments_page() {
remove_menu_page( 'edit-comments.php' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment