How to Add Custom Image Sizes to WordPress Uploader

WordPress 3.3 is finally out, and features a host of new improvements in the UI, along with other novelties.

A new feature I’m digging is the image_size_names_choose filter, which enables us to add new image sizes to the media upload/insert interface.

Check out the code below and the resulting screen:

if ( function_exists( 'add_image_size' ) ) {
	add_image_size( 'new-size', 300, 100, true ); //(cropped)
}

add_filter('image_size_names_choose', 'my_image_sizes');
function my_image_sizes($sizes) {
        $addsizes = array(
                "new-size" => __( "New Size")
                );
        $newsizes = array_merge($sizes, $addsizes);
        return $newsizes;
}

image_size_names_choose

If you enjoyed this post, make sure to subscribe to WP Mayor’s RSS feed.

About Jean Galea

Jean Galea is a WordPress developer, trainer and consultant. He is the founder of WP Mayor and is available for freelance work. You can get in touch via his website at www.jeangalea.com.

No related posts.

11 Responses

  1. Denny / initial-blog
    Denny / initial-blog December 19, 2011 at 11:40 | | Reply

    Hi, Thx for the tip, but, it doesn’t work on my website.

    i pasted your code in my function file and when i want to insert a pic, i can see my new size without dimension, but i can’t select it…

  2. Denny / initial-blog
    Denny / initial-blog December 19, 2011 at 11:47 | | Reply

    So, if the image was already uploaded, it seems to be KO, but if i upload a new image, it’s OK.

    Thx for your help, it will be usefull!

  3. Denny / initial-blog
    Denny / initial-blog December 19, 2011 at 11:52 | | Reply

    Anaother question: Can we use this custom image size in gallerie now?

  4. Michele
    Michele February 3, 2012 at 12:46 | | Reply

    Hi.
    i have created my new image size 300 x 100 like your example but if i upload an image with the same width and height i’m not able to select New Size but only Full Size.
    Any help is appreciated!

  5. Brendan
    Brendan February 9, 2012 at 19:43 | | Reply

    This is fantastic, great article.
    One thing, is there a way to have these custom image sizes show up in the “edit image” editor as well? So if I go to edit the photo in the uploader, when I go to crop it and apply, it only shows the wordpress defaults.

  6. neil
    neil February 15, 2012 at 11:03 | | Reply

    I tried the code and it generates the image in the upload folder but i don’t see the new option in the media upload screen. I’m using 3.3.1 this would be really useful for my client to able to choose image size based on location rather than dimension ie ‘main post’, ‘recent post’

    many thanks

    neil

  7. Matthew
    Matthew February 21, 2012 at 23:08 | | Reply

    is there a way to add multiple new sizes?

Leave a Reply