Offer Custom Image Sizes in the Editor
Adds your registered custom image sizes to the size dropdown in the block editor and media modal, so editors can pick them when inserting images.
Opens WPIDE on
Code
add_filter( 'image_size_names_choose', function ( $sizes ) {
// Registered size name => label shown to editors.
$labels = array(
'medium_large' => 'Medium large',
);
foreach ( wp_get_registered_image_subsizes() as $name => $size ) {
if ( ! isset( $sizes[ $name ] ) && isset( $labels[ $name ] ) ) {
$sizes[ $name ] = $labels[ $name ];
}
}
return $sizes;
} );
Notes
The sizes must already be registered with add_image_size(). Edit $labels to give them readable names.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.