This page redirects to an external site: https://developer.wordpress.org/reference/functions/get_intermediate_image_sizes/
Get the available image sizes
<?php get_intermediate_image_sizes(); ?>
var_dump( get_intermediate_image_sizes() );
array(4) {
[0]=>
string(9) "thumbnail"
[1]=>
string(6) "medium"
[2]=>
string(12) "medium_large"
[3]=>
string(5) "large"
[4]=>
string(10) "custom-size"
}
List available image sizes with width and height following
/**
* 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;
}
Some examples:
var_dump( get_image_sizes() );
/*
array(5) {
["thumbnail"]=>
array(3) {
["width"]=>
string(3) "150"
["height"]=>
string(3) "150"
["crop"]=>
bool(true)
}
["medium"]=>
array(3) {
["width"]=>
string(3) "300"
["height"]=>
string(3) "300"
["crop"]=>
bool(false)
}
["medium_large"]=>
array(3) {
["width"]=>
string(4) "768"
["height"]=>
string(4) "0"
["crop"]=>
bool(false)
}
["large"]=>
array(3) {
["width"]=>
string(4) "1024"
["height"]=>
string(4) "1024"
["crop"]=>
bool(false)
}
["juliobox-size"]=>
array(3) {
["width"]=>
int(211)
["height"]=>
int(279)
["crop"]=>
bool(false)
}
}
*/
var_dump( get_image_size( 'large' ) );
/*
array(3) {
["width"]=>
int(1024)
["height"]=>
int(1024)
["crop"]=>
bool(false)
}
*/
var_dump( get_image_size( 'foo-bar' ) ); /* bool(false) */
Since: 3.0
get_intermediate_image_sizes() is located in wp-includes/media.php