Last active
October 9, 2017 22:59
-
-
Save treetrum/35b78bacd174007aa96f73242b3de080 to your computer and use it in GitHub Desktop.
Remove comments on WordPress without a plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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