Disable Comments on Attachment Pages

This is a Developer Level doc.

If you're unfamiliar with PHP and/or editing files, codes and templates, as well as with resolving possible conflict, please seek help from a professional. Under our Support Policy, we don't provide support for modifications and customization.

If you would like to disable comments on attachment pages (usually images) and prevent spam, use the following PHP snippet:

// Disable comments on attachments.
function close_attachment_comments( $open, $post_id = null ) {
if ( is_attachment() ) {
$open = false;
}
return $open;
}
add_filter( 'comments_open', 'close_attachment_comments' );

All PHP snippets should be added via a child theme's functions.php file.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.