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

How to Disable Comments on WordPress Media Attachments

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
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 experts 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 »


  1. Frank says:

    Thanks, the code snippet worked just fine!

  2. Lola Catanese says:

    Hi I pasted the code and my site got corrupted..
    I went to back arrow and deleted the code but I could get into it anymore
    Pease help… site is

  3. Mohsin says:

    Hi dear
    I Pasted the code in wordpress theme’s functions.php file which resulted in removal of comments from my site. now I want to enable comments. I have deleted above code from functions.php file but still comments form is disabled from my site. How can I enable comments form….????

  4. kksilvery says:

    Hi Syed,

    I have installed and using your plugin for my client. I wanted to remove comment bar , i have used both of ur methods but it has not worked for me .

    Please help me out somehow. My client is asking to remove it.


  5. Robert Groenen says:

    Thank you, the plugin option worked fine. Hope to get rid of spammer comments now.

  6. [TiSiE] says:

    Note: The second parameter ($post_id) can be NULL (if comments_open() is called w/o parameter).

    So you should define your function “function filter_media_comment_status( $open, $post_id = null)”

    However, it only matters, if you set WP_DEBUG to true. Then you get a bunch of Notices about a missing second parameter and undefined variable.

  7. Trish says:

    How do I remove the iso/camera information

  8. Victor Bonilla says:

    It works sweeeet, and save me some spam problem I was having recently

  9. Becher says:

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

  10. Ryan Hellyer says:

    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 …

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

  11. Dan says:

    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?

  12. Simon Perrin says:

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

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

      Thank you Simon, it solved my problem!

    • Elisa says:

      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!

  13. Sudeep Acharya says:


    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.

    Sudeep Acharya

  14. Paul - Sports Photographer says:

    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.



    • Editorial Staff says:

      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.

  15. Ron Ladouceur says:

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

  16. Costa says:

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

  17. Billy Patton says:

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

    • Editorial Staff says:

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

      • Billy Patton says:

        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 ‘’ 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

  18. Gautam Doddamani says:

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

  19. MonkeyMays says:

    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!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.