Tom Maitland

Creates digital things at Agency. WordPress developer. Web designer. Communicates for UN Youth Australia.

Add Custom Image Sizes to WordPress Media Uploader

30 January 2013

Here’s a little trick to include custom image sizes as options in the WordPress 3.5+ media uploader for your themes. It means more image size options for your pages, with all the magical ease of WordPress’ image management and cropping.

Firstly create a function setting theme support for post thumbnails, and your custom sizes. Add that function to the after_theme_setup hook.

[codesyntax lang=”php”]

function custom_image_sizes() {
  add_theme_support('post-thumbnails');
	add_image_size('banner', 960, 355, true);
	add_image_size('thumb', 120, 120, true);
	add_image_size('widget', 170, 400, false);
}
add_action('after_setup_theme', 'custom_image_sizes');

[/codesyntax]

Then add the sizes you want to display to the uploaded through an array and the image_size_names_choose filter like so:

[codesyntax lang=”php”]

function add_custom_sizes( $imageSizes ) {
  $my_sizes = array(
		'banner' => 'Banner'
	);
	return array_merge( $imageSizes, $my_sizes );
}
add_filter( 'image_size_names_choose', 'add_custom_sizes' );

[/codesyntax]