I need to display the total number of images in my WP blog built?

asked Dec 10, 2012 in Website Builder by SunFun (3,000 points)
Hi again…
Can anyone please tell me how to display the total number of images, all the images in my media library?
Appreciate your advice

1 Answer

0 like 0 dislike
answered Dec 10, 2012 by expert (14,380 points)
Try this to count the  total number of jpg, gif, and png images in your media library

Add  this code  to your the functions.php file
function img_cnt(){
        $query_img_args = array(
                'post_type' => 'attachment',
                'post_mime_type' =>array(
                                'png' => 'image/png',
                                'gif' => 'image/gif',
                                'jpg|jpeg|jpe' => 'image/jpeg',
                'post_status' => 'inherit',
                'posts_per_page' => -1,
        $query_img = new WP_Query( $query_img_args );
        echo $query_img->post_count;
Add this code in the location you want to display the count total.