Get Registered Image Sizes with WordPress
Output a drop down list of registered image sizes by name
<?php
// Output a drop down list of registered image sizes by name
$image_sizes = get_intermediate_image_sizes(); ?>
<select name="image_size">
<?php foreach ($image_sizes as $size_name): ?>
<option value="<?php echo $size_name ?>"><?php echo $size_name ?></option>
<?php endforeach; ?>
</select>
Output a drop down list of registered image sizes by name
/**
* List registered image sizes with WordPress
*
* @return
*/
function my_list_additional_image_sizes() {
global $_wp_additional_image_sizes;
$sizes = array();
$get_intermediate_image_sizes = get_intermediate_image_sizes();
// Create the full array with sizes and crop info
foreach( $get_intermediate_image_sizes as $_size ) {
if ( in_array( $_size, array( 'thumbnail', 'medium', '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']
);
}
}
// Get only 1 size if found
if ( $size ) {
if( isset( $sizes[ $size ] ) ) {
return $sizes[ $size ];
} else {
return false;
}
}
echo '<pre>';
print_r ($sizes);
echo '</pre>';
}
add_action( 'init', 'my_list_additional_image_sizes', 900 );