Insert Custom Image Sizes into Select Boxes

This snippet allows you to select image sizes by name and dimensions in drop down boxes throughout WordPress.

Add this to mu-plugins/add_image_size.php
Change names and sizes as needed.

/* ADD CUSTOM IMAGE SIZES */
if ( function_exists( 'add_image_size' ) ) {
 add_image_size( 'portfolio-archive', 510, 400, true );
 add_image_size( 'portfolio-single', 768, 0, false );
}

add_filter( 'image_size_names_choose', 'ere_insert_custom_image_sizes' );
function ere_insert_custom_image_sizes( $sizes ) {
 global $_wp_additional_image_sizes;
 if ( empty($_wp_additional_image_sizes) )
 return $sizes;

foreach ( $_wp_additional_image_sizes as $id => $data ) {
 if ( !isset($sizes[$id]) )
 $sizes[$id] = ucfirst( str_replace( '-', ' ', $id ) );
 }

return $sizes;
}

See the example below

Insert-Custom-Image-Sizes-into-Select-Boxes

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Scroll to Top