SNIPPET · GRATUITO
Disabilita completamente i commenti WordPress
Rimuovi commenti e ping dal frontend e dalla dashboard senza cancellare i commenti già salvati.
Cosa fa
Chiude commenti e ping, rimuove il supporto commenti dai post type, blocca nuovi invii, nasconde i commenti esistenti e rimuove le principali voci commenti da wp-admin e REST API.
Importante. Non elimina i commenti già presenti nel database.
Come usarlo
- Installa il plugin gratuito Code Snippets.
- Crea un nuovo snippet PHP.
- Incolla il codice e attivalo ovunque.
/**
* Disable WordPress comments everywhere.
*
* Existing comments are not deleted; they are hidden from the frontend
* and the comment UI is removed from wp-admin.
*/
add_action( 'init', function () {
foreach ( get_post_types() as $post_type ) {
remove_post_type_support( $post_type, 'comments' );
remove_post_type_support( $post_type, 'trackbacks' );
}
}, 100 );
add_filter( 'comments_open', '__return_false', 20 );
add_filter( 'pings_open', '__return_false', 20 );
add_filter( 'comments_array', function () {
return array();
}, 10, 2 );
add_filter( 'get_comments_number', function () {
return 0;
}, 20, 2 );
add_filter( 'preprocess_comment', function ( $commentdata ) {
wp_die(
esc_html__( 'Comments are disabled on this website.', 'mrc-snippets' ),
'',
array( 'response' => 403 )
);
}, 0 );
add_action( 'admin_menu', function () {
remove_menu_page( 'edit-comments.php' );
remove_submenu_page( 'options-general.php', 'options-discussion.php' );
} );
add_action( 'admin_init', function () {
global $pagenow;
if ( in_array( $pagenow, array( 'edit-comments.php', 'options-discussion.php' ), true ) ) {
wp_safe_redirect( admin_url() );
exit;
}
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
} );
add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {
$wp_admin_bar->remove_node( 'comments' );
}, 999 );
add_filter( 'rest_endpoints', function ( $endpoints ) {
foreach ( $endpoints as $route => $handlers ) {
if ( strpos( $route, '/wp/v2/comments' ) === 0 ) {
unset( $endpoints[ $route ] );
}
}
return $endpoints;
} );
Come usarlo
- Installa Code Snippets Free su WordPress.
- Crea un nuovo snippet PHP.
- Copia e incolla il codice.
- Attivalo nell’ambito indicato.
È un metodo semplice, non obbligatorio: puoi integrare il codice nel tuo plugin o nel punto appropriato. Per gli esempi Gravity Forms configura gli ID e gli eventuali provider prima di attivare.