Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Disable Comments on WordPress Media Attachments

Last updated on by
Elegant Themes
How to Disable Comments on WordPress Media Attachments

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.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »
  • Becher

    Thank you; the php-code solved my problem :-)

  • Ryan Hellyer

    Thanks for the code snippet.

    I wanted this in a generic form I could use on multiple sites, so I made a plugin based on it … http://geek.ryanhellyer.net/products/disable-attachment-comments/

    I’ve linked back to this page in the plugin itself and on that page.

    • James Ralph

      Thank you so much for that plugin! Awesome.

  • Dan

    Hi, after using that code you have provided I am receiving an Internal Server Error message on all pages…

    Any idea why this has happened and how I can get back on please?

    • http://www.wpbeginner.com Editorial Staff

      Not sure why that would happen. Simply take out the code you added using FTP.

  • Simon Perrin

    There is a very easy way to turn these off if you are not confident playing with php. Simply open your images within the media library, then click on the ‘Screen Options’ tab at the top of the screen, then check the ‘Discussion’ check box. You should now see two checkboxes at the bottom of each Media file – ‘Allow Comments’ and ‘Allow Trackbacks’ turn those off, and you are done. The only problem is that it can take a long time to do this if you have lots of images.

    • Waldemar

      Hi, there’s no “Screen Options” tab when I open my images within the media library. Im using WP 3.4.1. do I need V. 3.6 ?

    • Anand

      Thank you Simon, it solved my problem!

    • Elisa

      Thank you Simon. It seems like the easiest. I had hoped it would also solve the temporary search for comments that flashes up on the screen, but the functions edit and this still have it starting up, then fading away. At least you can no longer use it.
      thanks again!

  • Sudeep Acharya

    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

  • Paul – Sports Photographer

    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

    • http://www.wpbeginner.com Editorial Staff

      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.

  • Ron Ladouceur

    I’m getting a “comments loading” message before comments disappear. Is this normal? It’s kinda visually annoying.

    • http://www.wpbeginner.com Editorial Staff

      You can always set the class to display:none if you like.

      • DANA HARGROVE

        Hi sorry, can you tell me how and where to enter the above to get rid of the loading comments bit in this plugin

  • Costa

    Thanks. This is a great tip and something that I have been asked many times.

  • http://www.facebook.com/profile.php?id=100000451897249 Billy Patton

    Out of curiosity does this work with post formats as well as the attachments/custom post types?

    • http://www.wpbeginner.com Editorial Staff

      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 :)

      • http://www.facebook.com/profile.php?id=100000451897249 Billy Patton

        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 :D

  • Gautam Doddamani

    a useful tutorial…btw did u add the “more on wpbeginner” section just now…it luks cool though :)

    • http://www.wpbeginner.com Editorial Staff

      Its always been there.

  • http://twitter.com/monkeymays MonkeyMays

    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!