Skip to content

Instantly share code, notes, and snippets.

@junaidbhura
Last active August 26, 2020 00:56
Show Gist options
  • Save junaidbhura/4d3701513a3167677a318c0151ab5dd0 to your computer and use it in GitHub Desktop.
Save junaidbhura/4d3701513a3167677a318c0151ab5dd0 to your computer and use it in GitHub Desktop.
WordPress remove comments globally
<?php
/**
* Remove support for comments globally.
*/
function jb_remove_comment_support() {
add_filter( 'comments_open', '__return_false' );
add_filter( 'pings_open', '__return_false' );
$post_types = get_post_types();
if ( ! empty( $post_types ) ) {
foreach ( $post_types as $post_type ) {
remove_post_type_support( $post_type, 'comments' );
remove_post_type_support( $post_type, 'trackbacks' );
}
}
add_action(
'admin_menu',
function () {
remove_menu_page( 'edit-comments.php' );
}
);
}
add_action( 'init', 'jb_remove_comment_support' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment