List all image sizes in a WordPress post

List all image sizes in a WordPress post

WordPress by default will generate 3 types of image sizes: thumbnail, medium and large.

Since version 2.9, WordPress has added post thumbnail feature that allows us to add more image sizes in order to use them more flexibly. If you are running a image based website, like Wallpaper download site, it’s always good to list all registered image sizes to let the uses choose their preferred resolution.

Keep reading and you’ll find it’s such an easy task. And below is the screenshot of our final result.

List all image sizes in a WordPress post
List all image sizes in a WordPress post

All image sizes generated by add_image_size function will be added to a global variable $_wp_additional_image_sizes.

Using global variable is not a good idea sometimes because someday WordPress will change it. Good news is that there is a function get_intermediate_image_sizes that will return an array of available image sizes.

Just drop following codes to somewhere in the loop of your single.php or any other file that display the post content.

This function requires a featured thumbnail to work well, it will display all image sizes of the thumbnail. If no thumbnail set, nothing will display.

Further reading:

https://codex.wordpress.org/Function_Reference/get_intermediate_image_sizes

Creating an Advanced Attachment Page in WordPress


http://www.deluxeblogtips.com/2011/06/list-registered-image-sizes.html

Save

Author: Leo

My name is Leo who's behind this blog. I've been working with wordpress since 2010. I'll write about themes, plugins, tutorials and all about wordpress here. Hope you find it useful!

Leave a Reply

Your email address will not be published. Required fields are marked *