Add custom image sizes to media windows

I was surprised to find that WordPress doesn’t automatically add custom image sizes to the Add Media popup.

Here’s a simple fix based on a function from the exhaustive article by over at WPMU.org.

The following function, when pasted into the bottom of your theme’s functions.php file, will add the custom sizes to the media window, as seen in the screenshot.

add_filter( 'image_size_names_choose', 'ml_custom_image_choose' );
function ml_custom_image_choose( $args ) {

	global $_wp_additional_image_sizes;

	// make the names human friendly by removing dashes and capitalising
	foreach( $_wp_additional_image_sizes as $key => $value ) {
		$custom[ $key ] = ucwords( str_replace( '-', ' ', $key ) );
	}

	return array_merge( $args, $custom );
}

I usually use the excellent Simple Image Sizes plugin, which mostly works on WP3.5, but if you’re using any funky media functions, I’d love to hear about it!