WordPress | Get a list of all the possible thumbnail sizes set within a theme
This time i need to work on a customer website developed by a colleague, i don’t know witch images size he had registered.
So, i need print a list of all images sizes.
Addi this code whet ever you want the list will be print.
print_r(get_intermediate_image_sizes());
If you need Name and sizes :
Add this in your function file:
/** * Get size information for all currently-registered image sizes. * * @global $_wp_additional_image_sizes * @uses get_intermediate_image_sizes() * @return array $sizes Data for all currently-registered image sizes. */ function get_image_sizes() { global $_wp_additional_image_sizes; $sizes = array(); foreach ( get_intermediate_image_sizes() as $_size ) { if ( in_array( $_size, array('thumbnail', 'medium', 'medium_large', 'large') ) ) { $sizes[ $_size ]['width'] = get_option( "{$_size}_size_w" ); $sizes[ $_size ]['height'] = get_option( "{$_size}_size_h" ); $sizes[ $_size ]['crop'] = (bool) get_option( "{$_size}_crop" ); } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) { $sizes[ $_size ] = array( 'width' => $_wp_additional_image_sizes[ $_size ]['width'], 'height' => $_wp_additional_image_sizes[ $_size ]['height'], 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'], ); } } return $sizes; } /** * Get size information for a specific image size. * * @uses get_image_sizes() * @param string $size The image size for which to retrieve data. * @return bool|array $size Size data about an image size or false if the size doesn't exist. */ function get_image_size( $size ) { $sizes = get_image_sizes(); if ( isset( $sizes[ $size ] ) ) { return $sizes[ $size ]; } return false; } /** * Get the width of a specific image size. * * @uses get_image_size() * @param string $size The image size for which to retrieve data. * @return bool|string $size Width of an image size or false if the size doesn't exist. */ function get_image_width( $size ) { if ( ! $size = get_image_size( $size ) ) { return false; } if ( isset( $size['width'] ) ) { return $size['width']; } return false; } /** * Get the height of a specific image size. * * @uses get_image_size() * @param string $size The image size for which to retrieve data. * @return bool|string $size Height of an image size or false if the size doesn't exist. */ function get_image_height( $size ) { if ( ! $size = get_image_size( $size ) ) { return false; } if ( isset( $size['height'] ) ) { return $size['height']; } return false; }
and then, where you want to print the array :
var_dump( get_image_sizes() );
and this is the result: