Family Encyclopedia >> Electronics

How to Disable Comments on WordPress Media Attachments: Simple Guide

Our team recently launched a powerful WordPress plugin that delivers stunning gallery carousels without relying on Jetpack. It transforms galleries into immersive full-screen experiences complete with navigation and comments. When a user asked how to disable comments specifically on media attachments, we put together this straightforward guide based on our hands-on development experience.

Add the following code snippet to your theme's functions.php file or a custom site-specific plugin. This filter checks the post type and closes comments for attachments only.

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

Prefer a no-code solution? Install the free Disable Comments plugin. It lets you selectively disable comments on post types like posts, pages, or media attachments—just enable the media option and save.

This approach keeps your site clean and performant. We've tested it across numerous setups to ensure reliability.