WordPress: Completely hide comments by content type

This code can be very useful if you are using a theme in your site that doesn’t have an option to completely remover comments from a post or page. The code will allow you to remove the comments by content type. Modify the code (array) to suit your needs.

Like always add the code in functions.php file inside your theme.

function hide_content_type_comments( $comments, $postid ){
    if( is_tax() ) //make sure is not a taxonomy page
        return $comments;

    $type = get_post_type( $postid )
    if( $type || in_array( $type, array('page','ims_gallery','photos') )  )
        return array( );
    return $comments;
}add_filter( 'comments_array', 'hide_content_type_comments');