WordPress Shortcode to get Total number of Images in a Site

Here’s a shortcode to get the total number of images uploaded to the entire website in WordPress.

Shortcode: [total_images]

Code for the shortcode:

//To get total images uploaded
function sw_total_images () {
$count = array_sum( (array) wp_count_attachments( $mime_type = 'image' ) );
return $count;
}
add_shortcode('total_images','sw_total_images');
PHP

Wherever you want to display the total images at site level, you can simply use the [total_images] shortcode.

Related:

How to add this code to your WordPress site

Leave a Comment