wp_get_registered_image_subsizes()
Gets the data (width, height, crop) of the currently registered image sizes.
Use get_intermediate_image_sizes() when you need to get only the names of intermediate sizes, not all the data.
No Hooks.
Returns
Array[]. An associative array of arrays with information about the sub-sizes of images:
Array [thumbnail] => Array [width] => 150 [height] => 150 [crop] => 1 [medium] => Array [width] => 300 [height] => 300 [crop] => ...
Usage
wp_get_registered_image_subsizes();
Examples
#1 Getting all thumbnail sizes
$sizes = wp_get_registered_image_subsizes();
foreach ( $sizes as $key => $val ) {
echo "Name: {$key};" . PHP_EOL;
echo "Width: {$val['width']}" . PHP_EOL;
echo "Height: {$val['height']}" . PHP_EOL;
if ( is_array($val['crop']) ) {
echo "Crop: {$val['crop'][0]}x{$val['crop'][1]}." . PHP_EOL;
} else {
echo "Crop: {$val['crop']}." . PHP_EOL;
}
echo PHP_EOL;
}
We will get:
Name: thumbnail; Width: 150 Height: 150 Crop: 1. Name: medium; Width: 300 Height: 300 Crop: . Name: medium_large; Width: 768 Height: 0 Crop: . Name: large; Width: 1024 Height: 1024 Crop: .
#2 Demo: what the function outputs
$sizes = wp_get_registered_image_subsizes(); print_r( $sizes ); /* Array ( [thumbnail] => Array ( [width] => 150 [height] => 150 [crop] => 1 ) [medium] => Array ( [width] => 300 [height] => 300 [crop] => ) [medium_large] => Array ( [width] => 768 [height] => 0 [crop] => ) [large] => Array ( [width] => 1024 [height] => 1024 [crop] => ) [1536x1536] => Array ( [width] => 1536 [height] => 1536 [crop] => ) [2048x2048] => Array ( [width] => 2048 [height] => 2048 [crop] => ) [post-thumbnail] => Array ( [width] => 1568 [height] => 9999 [crop] => ) ) */
Changelog
| Since 5.3.0 | Introduced. |