Count total number of jpg, gif, png images in media library

Adding the first snippet to the functions.php of your wordpress theme will display a count of all images within the media library. Add the second snippet in the location you wish to display the count total.

Code Snippet:

function 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 $query_img->post_count;

Code Snippet:


Comments  Leave a Reply

  1. Cliff Paulick May 1, 2012 at 9:44 am

    Isn’t this part of WP core? I’m using 3.3.2 and it’s already there without this snippet.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!