WordPress creates an attachment page automatically for every media that is been uploaded through WordPress’s media uploader, be it photo, image, graphic, video, audio, ZIP file and etc. The attachment page is in fact identical to any other posts or pages, where it may also allow visitors to post comments on media attachment page if you don’t disable the option to “allow people to post comments on new articles” in “Settings” -> “Discussion”.

Spam on Media Attachment Page

WordPress basically provides two basic built-in ways to disable the comments on media or attachment pages, one which mentioned above.

Method 1: Disable Comments BEFORE Uploading Media

When you disable comments on all new posts and pages, the newly uploaded media will inherit the settings too, unless overridden in individual post level.

  1. Go to Settings -> Discussion.
  2. Uncheck the Allow people to post comments on new articles checkbox under “Default article settings” section.

    You may also want to deselect the Allow link notifications from other blogs (pingbacks and trackbacks) option.

    Disable Comments in WordPress

  3. Click Save Changes when done.
  4. Upload your media.
  5. Re-enable comments for new posts if you wish.

Method 2: Close Comments on Each Media or Attachment Pages Individually

It’s possible to go to post details page of each media or attachment, and disable their comments and/or trackbacks and pingbacks feature.

  1. Go to Media -> Library.
  2. Open each media, and then go to Edit more details link.

    Media Page Options

  3. Deselect the Allow comments under “Discussion” section, just like a standard posts or pages page in WordPress.

    You may also want to disable Allow trackbacks and pingbacks on this page.

    Close WordPress Comments in Media Attachment

    If you don’t see the Discussion section, click on Screen Options below the Toolbar to expand the options, then select Discussion.
  4. Click on Update when done.

Method 3: Through WordPress API Hooks (Actions and Filters) or Plugins

If you have hundreds or thousands of media uploaded with comments opened, unfortunately, WordPress does not provide an easy way to close the comments on media attachments page for existing media. However, WordPress API provides hooks which can be used to close and disable the comments features on all media pages and attachments globally and automatically.

To actually close comments on a page, WordPress requires “comment_status” (and “ping_status” for pingbacks and trackbacks) value in database to be “closed”. Or a comment attempting to post to an attachment or media page has to be stopped right before it’s been posted to database. That’s why some solution for disabling comments on media page which based on “comments_open” as shown in below code does not work, as the conditional tag checks if a page is opened for comments when presenting the template, but spam does not require any comment form!

Example of code that does not actually work:

function disable_media_comment( $open, $post_id ) {
if( get_post_type( $post_id ) == 'attachment' ) {
return false;
return $open;
add_filter( 'comments_open', 'disable_media_comment', 10 , 2 );

In the active theme’s functions.php, add in the following function:

function disable_media_comments( $post_id ) {
	if( get_post_type( $post_id ) == 'attachment' ) {
		wp_die("Comment not allowed.");
	return $open;
add_action( 'pre_comment_on_post', 'disable_media_comments' );

Alternatively, you can modify the database so that the “comment_status” for attachment post type become “closed”. To do so, you can run the following SQL query in phpMyAdmin or MySQL client on your WordPress database:

UPDATE `wp_posts` SET `comment_status` = 'closed' WHERE `post_type` = 'attachment' AND `comment_status` = 'open';

If you want to disable pingbacks and trackbacks too:

UPDATE `wp_posts` SET `comment_status` = 'closed', ping_status = 'closed' WHERE `post_type` = 'attachment' AND `comment_status` = 'open';

Last but not least, you can make sure of WordPress plugins to do the job for you, thought you have to be careful with the settings as they can do much more that simply close the comments on attachment page. Some plugins include Disable Comments and Comment Control. It’s possible to uninstall the plugins after the job is done after the change is made in database, and not depending on plugin for it to work.

You can also use a WordPress hook to enforce disabling of attachment (media) comments in database when uploading.