WordPress Snippets at WPcustoms

Count total number of images in media library

show a total number of images you currently host


/**
 * Snippet Name: Count total number of images in media library
 * Snippet URL: https://wpcustoms.net/snippets/count-total-number-images-media-library/
 */
  function wpc_img_count(){
  $query_img_args = array(
    'post_type' => 'attachment',
    'post_mime_type' =>array(
                    'jpg|jpeg|jpe' => 'image/jpeg',
                    'gif' => 'image/gif',
        'png' => 'image/png',
        ),
    'post_status' => 'inherit',
    'posts_per_page' => -1,
    );
  $query_img = new WP_Query( $query_img_args );
  echo 'You currently host ' .$query_img->post_count. ' images.';
}