Attachments no comments and no google indexing

If you do not want attachmentpages to be indexed and you do not want comments on them

// no comments on attachments

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

// do not index attachment pages

function attachmentpages_noindex() {
if(is_attachment()) {

echo '<meta name="robots" content="noindex" />';

}
}
add_action('wp_head', 'attachmentpages_noindex');