fbpx
// Add other useful image sizes for use through Add Media modal
add_image_size( 'medium-width', 480 );
add_image_size( 'medium-height', 9999, 480 );
add_image_size( 'medium-something', 480, 480 );

// Register the three useful image sizes for use in Add Media modal
add_filter( 'image_size_names_choose', 'wpshout_custom_sizes' );
function wpshout_custom_sizes( $sizes ) {
    return array_merge( $sizes, array(
        'medium-width' => __( 'Medium Width' ),
        'medium-height' => __( 'Medium Height' ),
        'medium-something' => __( 'Medium Something' ),
    ) );
}

The comments in the code itself pretty much explain what’s going on, as will the rest of this post; but here are two quick notes that should help you get an early grasp on the code:

ADD_IMAGE_SIZE() ARGUMENTS

add_image_size() takes four arguments:

  1. name, a string (required)
  2. width, an integer (optional)
  3. height, an integer (optional)
  4. crop, a boolean (optional)

name explains itself. width and height are target size values, in pixels. We’ll explain how they work (and how they work with crop) below.

WPSHOUT_CUSTOM_SIZES()

All you need to know about that function is that WordPress requires some boilerplate code in order to add custom image sizes into the “Add Media” modal—where site users can use them—and to define what name those sizes go by in the “Add Media” environment. Hooking into a filter hook calledimage_size_names_choose and registering the three desired image sizes are allwpshout_custom_sizes() does; here’s the result:

insert_into_post