Quick and easy way to add, disable and use only those image sizes you want in the WordPress Media Uploader.
All codes go inside your active theme’s functions.php
file.
Add Custom Image Sizes in WordPress
add_image_size('magazine-thumb', 120, 120, true); //crop add_image_size('slideshow-thumb', 250, 220, false); add_image_size('sidebar-thumb', 85, 85, true); //crop
Access Custom Image Sizes in WordPress Media Uploader
To use these newly added image sizes in Media Uploader, we are going to use image_size_names_choose
filter introduced in WordPress 3.3
function custom_wmu_image_sizes($sizes) { $myimgsizes = array( "magazine-thumb" => __( "Magazine" ), "slideshow-thumb" => __( "Slideshow" ), "sidebar-thumb" => __( "Sidebar" ) ); $newimgsizes = array_merge($sizes, $myimgsizes); return $newimgsizes; } add_filter('image_size_names_choose', 'custom_wmu_image_sizes');
Disable Unwanted Image Sizes in WordPress Media Uploader
Now that you have added your custom image sizes, you can choose to disable creation of thumbnails for default sizes with the following code. If your theme adds any image size, you can disable that as well similarly.
function remove_wmp_image_sizes( $sizes) { unset( $sizes['thumbnail']); unset( $sizes['medium']); unset( $sizes['large']); return $sizes; } add_filter('intermediate_image_sizes_advanced', 'remove_wmp_image_sizes');
Update: The above function did disable creation of default image sizes, but their radio buttons were still visible in the Media Uploader. To remove those radio buttons as well, you can use this single function instead of the earlier two:
function custom_wmu_image_sizes($sizes) { unset( $sizes['thumbnail']); unset( $sizes['medium']); unset( $sizes['large']); unset( $sizes['full'] ); // removes full size if needed $myimgsizes = array( "magazine-thumb" => __( "Magazine" ), "slideshow-thumb" => __( "Slideshow" ), "sidebar-thumb" => __( "Sidebar" ) ); $newimgsizes = array_merge($sizes, $myimgsizes); return $newimgsizes; } add_filter('image_size_names_choose', 'custom_wmu_image_sizes');
Thanks Sébastien.
8 thoughts on “Add, Disable & Use Custom Image Sizes in WordPress 3.3 Media Uploader”
hi,
thanx for the tips 🙂
playing a bit with your code, i found that if you are using
remove_wmp_image_sizes
function then you probably also want to remove the radio buttons that should allow the unwanted types to be selected…if so, you may do like this :
function custom_wmu_image_sizes($sizes) {
unset( $sizes['thumbnail'] );
unset( $sizes['medium'] );
unset( $sizes['large'] );
unset( $sizes['full'] ); // removes full size if needed
$myimgsizes = array(
"magazine-thumb" => __( "Magazine" ),
"slideshow-thumb" => __( "Slideshow" ),
"sidebar-thumb" => __( "Sidebar" )
);
$newimgsizes = array_merge($sizes, $myimgsizes);
return $newimgsizes;
}
seb.
Thanks for the tip Sébastien. I have updated the post with your method. 🙂
Thans Sébastien & Renji, i tried it with the code above.
But i cannot get the new image sizes to work.
My code is at this moment:
add_image_size('magazine-thumb', 120, 120, true); //crop
add_image_size('slideshow-thumb', 250, 220, false);
add_image_size('sidebar-thumb', 85, 85, true); //crop
function custom_wmu_image_sizes($sizes) {
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['large']);
unset( $sizes['full'] ); // removes full size if needed
$myimgsizes = array( );
$newimgsizes = array_merge($sizes, $myimgsizes);
return $newimgsizes;
}
add_filter('image_size_names_choose', 'custom_wmu_image_sizes');
It removes the empty (not used types) but do you know what the bug is? =)
hi,
well, as you remove the 4 default image sizes with
unset
and don’t give a new list (your$myimgsizes
array is empty !) then all radio buttons must have disappeared 🙂you must fill the
$myimgsizes
array with your new sizes (as in Renji exemple) :$myimgsizes = array(
"magazine-thumb" => __( "Magazine" ),
"slideshow-thumb" => __( "Slideshow" ),
"sidebar-thumb" => __( "Sidebar" )
);
seb
I added this to the functions.php file, but nothing happened. It still shows the original options. Do I need to restart anything? I’m on iPage hosting, so I believe I can’t restart the server
Your code examples are close to invisible.
I want to remove the full size image and want to upload medium size image
I tried
unset( $sizes[‘full’] );
but its not working for me, full size image radio button is still there
Great stuff! Thank you!
There is one moment: if you’ve unset all built-in sizes including full-size, you have to return $myimgsizes instead of merging arrays. So the last lines in the function should be: