25% off ProSNIPC25OFF

Disable Comments on Attachments

Prevents comments and pings from being opened on media attachment posts.

PHPby SnipCraft
php
<?php
add_filter( 'comments_open', 'scseed_disable_attachment_comments', 10, 2 );
add_filter( 'pings_open',    'scseed_disable_attachment_comments', 10, 2 );
if ( ! function_exists( 'scseed_disable_attachment_comments' ) ) {
    function scseed_disable_attachment_comments( $open, $post_id ) {
        return ( 'attachment' === get_post_type( $post_id ) ) ? false : $open;
    }
}

// Remove the comment reply link on attachment pages.
add_filter( 'comment_reply_link', 'scseed_no_attachment_reply_link', 10, 4 );
if ( ! function_exists( 'scseed_no_attachment_reply_link' ) ) {
    function scseed_no_attachment_reply_link( $link, $args, $comment, $post ) {
        return ( 'attachment' === get_post_type( $post ) ) ? '' : $link;
    }
}
#attachments#comments#media#spam