How to Disable Comments on Attachments in WordPress

Many of spammers target to media attachments on your WordPress website for comments. You can disable comments on your media attachments by using WordPress plugin or adding custom PHP code in your theme file. Below is the two methods described to disable comments on media attachments.

Method 1 – Using Plugin

Disable Comments WordPress plugin provides and option to disable comments globally on your WordPress website. This plugin allows you to disable all type of comments like post comments, pages comments, and media comments.
Disable Comments on Attachments

Method 2 – Using PHP Code

If you don’t want to use any plugin, You can disable media comments by adding custom code in your WordPress theme. Edit functions.php in your WordPress theme file and append following code. This will disable comments on your media posts.
 function add_filter_media_comment ( $open, $post_id ) {  $post = get_post( $post_id );  if( $post->post_type == 'attachment' ) {   return false;  }  return $open; } add_filter( 'comments_open', 'add_filter_media_comment', 10 , 2 ); 

Thanks for Visit Here

Comments