Add, Disable & Use Custom Image Sizes in WordPress 3.3 Media Uploader

Print Page

Quick and easy way to add, disable and use only those image sizes you want in the WordPress Media Uploader.

Images Sizes in 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”

Comments are closed.