Warning: include(/home/185104/domains/s185104.gridserver.com/html/wp-content/plugins/wp-synhighlight/object.php) [function.include]: failed to open stream: No such file or directory in /nfs/c06/h05/mnt/185104/domains/tommaitland.net/html/wp-config.php on line 42

Warning: include() [function.include]: Failed opening '/home/185104/domains/s185104.gridserver.com/html/wp-content/plugins/wp-synhighlight/object.php' for inclusion (include_path='.:/usr/local/php-5.3.29/share/pear') in /nfs/c06/h05/mnt/185104/domains/tommaitland.net/html/wp-config.php on line 42
Add Custom Image Sizes to WordPress Media Uploader - Tom Maitland

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]