Add custom image sizes, the right way

Since version 2.9, WordPress supports custom image sizes that will be used to create thumbnails of image attachments. Adding new image sizes is pretty easy; in your theme’s functions.php file, add this block of code:

function mytheme_add_image_sizes() {
    add_image_size( 'small_thumb', 50, 50, true );
}
add_action( 'after_setup_theme', 'mytheme_add_image_sizes' );

… and you’re done. Now, everytime a new image is uploaded, a 50×50 thumbnail with be created for you.

However, this new image size won’t show up when you want to insert an image into a post:

Image size dropdown on Insert Media frame
Image size dropdown on Insert Media frame

The solution is pretty simple too; add this bit of code into your theme’s functions.php file:

function mytheme_image_size_names( $sizes ) {
    $sizes['small_thumb'] = __( 'Small Thumb', 'mytheme' );

    return $sizes;
}
add_filter( 'image_size_names_choose', 'mytheme_image_size_names' );

Now you can select your custom image size from the dropdown:

Image size dropdown on Insert Media frame, with custom image sizes.
Image size dropdown on Insert Media frame, with custom image sizes.

Notes: