Recently we released a plugin that lets you add a beautiful gallery carousel in WordPress without Jetpack. One of the features of that plugin is that it turns your gallery into an immersive full screen experience with navigation, comments etc. One of our users asked us if there was a way to get rid of the comments feature from those attachments. In this article, we will show you how to disable comments on WordPress media attachments.
Paste the following code in your theme’s functions.php file or a site-specific plugin.
function filter_media_comment_status( $open, $post_id ) {
$post = get_post( $post_id );
if( $post->post_type == 'attachment' ) {
return false;
}
return $open;
}
add_filter( 'comments_open', 'filter_media_comment_status', 10 , 2 );
If you don’t like to deal with code, then simply download the plugin called Disable Comments. This plugin allows you to globally disable comments on a specific post type such as (Post, Pages, Media). Just select the media option.
We hope that you found this article helpful.







Hi,
I have tried both procedure to remove comments.
In the first case the message field was not removed from media and in the second the plugin was just incompatible with this plugin.
Regards,
Sudeep Acharya
Fab plugin that as a photographer works perfectly. A quick question though. How to you rid everything other than image from the code? I want just photos, no titles, descriptions, download full size.
Thanks.
Paul
You would have to edit the plugin file to get rid of all the information. At which point, you are just as well off with a lightbox plugin.
I’m getting a “comments loading” message before comments disappear. Is this normal? It’s kinda visually annoying.
You can always set the class to display:none if you like.
Thanks. This is a great tip and something that I have been asked many times.
Out of curiosity does this work with post formats as well as the attachments/custom post types?
Yes I think it could work with that too. Instead of targeting the post_type, you would have to target the taxonomy “post_format”. Then term which would be like post-format-quote. Basically get_posts accept WP_Query parameters. You can play around with it
Ahh, yes of course. It’s one of those “the answer is staring you right in the face but your too close to see it” type moments. Now I wonder how many places I can drop this into before my site looses all user interactions haha
I have a ‘delicio.us’ like bookmarking section on my personal site using the “link” post format and no matter what kind of anti-spam methods I try the spambots still manage to comment… or at least they will be able to for the next 2 minutes then… POOF! No more spam comments, all thanks to WPBeginner
a useful tutorial…btw did u add the “more on wpbeginner” section just now…it luks cool though
Its always been there.
Great! I’ve had one image on a site keep getting slammed with spam comments day after day. I just pulled up the attachment page and no more comments form. Thanks!