Prevent WordPress Comments on Media Attachment Pages (Images, Videos)

Advertisement

If you attach an image or video on WordPress post you can link URL to file URL, attachment post URL or just simply select none. So people who visit the image, when they click it – will be taken to the image file directly or a separate WordPress page template with the attachment image/video. If you had selected the second option “attachment post URL” – the image will be shown in a separate WordPress page template which has comments enabled.

If you want to disable comments on such media attachment pages, there are two ways – 1) Disable comments plugin 2) Tweaking the functions PHP file. If you feel the first option will take load on your server, you can implement the second option. It’s very easy to tweak on functions php file to disable comments on media attachment pages.

There are default options in WordPress to disable comments on a specific post or page. But, there is no option to specify disable comments on media attachment pages. The Disable comments plugin will globally disable comments on any post type (posts, pages, attachments, etc.)

Below code, paste in your functions.php file. If you’re using Thesis or any other framework that doesn’t have functions.php, then implement it on custom_functions.php file.

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

Why should every one implement this feature on their WordPress blogs, because sometimes a single media attachment page will get slammed by spam comments daily? If you disable comments on media attachment pages, it’s a big relief.

For a limited time I'm sharing some select Tips and Tricks and How-To Guides for FREE.

Speak Your Mind

*