Using WordPress ‘image_size_names_choose’ PHP filter

The image_size_names_choose WordPress PHP Filter allows you to modify the list of image size names and labels available in the WordPress Media Library.

Usage

add_filter('image_size_names_choose', 'my_custom_image_sizes');
function my_custom_image_sizes($size_names) {
    // your custom code here
    return $size_names;
}

Parameters

  • $size_names (array) – An associative array of image size labels keyed by their name. Default values include ‘Thumbnail’, ‘Medium’, ‘Large’, and ‘Full Size’.

More information

See WordPress Developer Resources: image_size_names_choose

Examples

Add a custom image size to the Media Library

Add a custom image size called ‘Custom Size’ with a width of 300px and a height of 200px. Make it available for selection in the WordPress admin.

add_image_size('custom_size', 300, 200, true);

add_filter('image_size_names_choose', 'my_custom_image_sizes');
function my_custom_image_sizes($size_names) {
    $size_names['custom_size'] = __('Custom Size');
    return $size_names;
}

Rename the default image sizes

Change the names of the default image sizes in the WordPress Media Library.

add_filter('image_size_names_choose', 'rename_image_sizes');
function rename_image_sizes($size_names) {
    $size_names['thumbnail'] = __('Small Thumbnail');
    $size_names['medium'] = __('Medium Size');
    $size_names['large'] = __('Big Size');
    return $size_names;
}

Remove default image sizes from the Media Library

Remove the ‘Medium’ and ‘Large’ image sizes from the WordPress Media Library.

add_filter('image_size_names_choose', 'remove_default_image_sizes');
function remove_default_image_sizes($size_names) {
    unset($size_names['medium']);
    unset($size_names['large']);
    return $size_names;
}

Add multiple custom image sizes

Add two custom image sizes (‘Small Banner’ and ‘Large Banner’) to the WordPress Media Library.

add_image_size('small_banner', 600, 300, true);
add_image_size('large_banner', 1200, 600, true);

add_filter('image_size_names_choose', 'add_multiple_image_sizes');
function add_multiple_image_sizes($size_names) {
    $size_names['small_banner'] = __('Small Banner');
    $size_names['large_banner'] = __('Large Banner');
    return $size_names;
}

Combine custom image sizes and renaming

Add a custom image size called ‘Custom Size’ and rename the default ‘Thumbnail’ size to ‘Small Thumbnail’.

add_image_size('custom_size', 300, 200, true);

add_filter('image_size_names_choose', 'custom_sizes_and_rename');
function custom_sizes_and_rename($size_names) {
    $size_names['thumbnail'] = __('Small Thumbnail');
    $size_names['custom_size'] = __('Custom Size');
    return $size_names;
}