Select Page

Why?
On some of my WordPress websites, spammers were commenting on random images. A feature to disable this through standard WordPress interface, seems not so obvious.

So I found a quick way (at least for me).

Create a simple WordPress plugin (create a folder e.g. disable-comments-media). Create a file inside the folder: e.g. disable-comments-media.php and copy / paste the code below.
Zip the folder and install/upload it to your WordPress, activate and you are good to go.

<?php
/*
Plugin Name: disable-comments-media
Description: disable-comments-media
*/
/* Start Adding Functions Below this Line */
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 );
  
/* Stop Adding Functions Below this Line */
?>