Skip to content

Instantly share code, notes, and snippets.

@GarySwift
Forked from twesolowski/list_thumbnail_sizes.php
Last active December 17, 2020 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GarySwift/581bdcb585b8ab89a2da02c8dffb9687 to your computer and use it in GitHub Desktop.
Save GarySwift/581bdcb585b8ab89a2da02c8dffb9687 to your computer and use it in GitHub Desktop.
Wordpress - get all defined thumbnail sizes
<?php
function list_thumbnail_sizes($type = 'all', $name = '') {
global $_wp_additional_image_sizes;
$sizes = array();
$rSizes = array();
foreach (get_intermediate_image_sizes() as $s) {
$sizes[$s] = array(0, 0);
if (in_array($s, array('thumbnail', 'medium', 'large'))) {
$sizes[$s][0] = get_option($s . '_size_w');
$sizes[$s][1] = get_option($s . '_size_h');
} else {
if (isset($_wp_additional_image_sizes) && isset($_wp_additional_image_sizes[$s]))
$sizes[$s] = array($_wp_additional_image_sizes[$s]['width'], $_wp_additional_image_sizes[$s]['height'],);
}
}
foreach ($sizes as $size => $atts) {
if ($type == 'width') {
$rSizes[$size] = $atts[0];
}
elseif ($type == 'height') {
$rSizes[$size] = $atts[1];
}
else {
$rSizes[$size] = $size . ' ' . implode('x', $atts);
}
}
if ($name && isset($rSizes[$name])) {
return $rSizes[$name];
}
return $rSizes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment