Cara Disable, Enable Komentar WordPress Tanpa Plugin

Non-aktifkan semua fitur komentar wordpress tanpa plugin menambahkan kode php pada file tema functions.php

Temukan file : menu tampilan > editor bekas tema > pilih tema > functions.php

Cara ini berhasil menghilangkan form komentar dihalaman, post namun tidak menghapus data komentar yang sudah ada.

 

Disable Komentar Post, Page

Kode PHP :

/* 1. Disable Comments on ALL post types */ 
function updated_disable_comments_post_types_support() {
$types = get_post_types();
foreach ($types as $type) {
if(post_type_supports($type, 'comments')) {
remove_post_type_support($type, 'comments');
remove_post_type_support($type, 'trackbacks');
}}}
add_action('admin_init', 'disable_comments_post_types_support');

/* 2. Hide any existing comments on front end */ 
function disable_comments_hide_existing_comments($comments) {
$comments = array();
return $comments;}
add_filter('comments_array', 'disable_comments_hide_existing_comments', 10, 2);

/* 3. Disable commenting */ 
function disable_comments_status() {
return false;}
add_filter('comments_open', 'disable_comments_status', 20, 2);
add_filter('pings_open', 'disable_comments_status', 20, 2);

 

Enable Komentar Post

Kode PHP enable komentar berguna menampilkan form komentar pada post type artikel.

/* open comment post */
FUNCTION FILTER_JOB_COMMENT_STATUS( $open, $post_id ) {
global $post;
$post = GET_POST( $post_id );
IF( $post->post_type == 'post' ) {
return true;
} } 

ADD_FILTER('comments_open', 'FILTER_JOB_COMMENT_STATUS', 10 , 2 );

READ :  List High Rates CPC, cPM Adsense 2024 By Country