WordPress Attachment Display Settings

Oh, cool! With add_image_size() your theme now generates 3 sizes of each uploaded image. Those, in addition to the 3 generated automatically by WordPress brings the total to 6. That’s 6 different versions of every single image!

Once we’ve defined our versions of image sizes (butter-regular, butter-medium and butter-large) — and since by default WordPress doesn’t do it for us — we’ll add the ability to select our image sizes from the Attachment Display Settings interface.

At this point, only the 3 WordPress generated image sizes are selectable from the display settings.

It would be nice if you could, when writing a post, insert the desired size image simply by selecting it from the drop-down menu just as simply as you would for the WordPress default sizes.

To do this, we add the following to our functions.php:

// show our custom image sizes when inserting media
function butter_show_image_sizes($sizes) {
  $sizes['butter-regular'] = __( 'Our Regular Size', 'butter' );
  $sizes['butter-medium'] = __( 'Our Medium Size', 'butter' );
  $sizes['butter-large'] = __( 'Our Large Size', 'butter' );
  return $sizes;
}
add_filter('image_size_names_choose', 'butter_show_image_sizes');

With that in place, as a user writes a post and needs to insert an image, she can select it easily from the WP UI.