Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show custom image sizes in the wordpress editor and media dialog. See https://since1979.dev/snippet-001-adding-custom-images-sizes/
<?php
/**
* custom_image_sizes_in_select.
*
* Add custom images sizes the the size selector in
* the gutenberg editor and the media modal.
*
* @see https://since1979.dev/snippet-001-adding-custom-images-sizes/
*
* @uses array_merge https://www.php.net/manual/en/function.array-merge.php
* @uses __() https://developer.wordpress.org/reference/functions/__/
*/
function custom_image_sizes_in_select($sizes)
{
return array_merge($sizes, array(
'full-page-width' => __('Full page width'),
'half-page-width' => __('Half page width'),
'square' => __('Square'),
));
}
/**
* Hook: image_size_names_choose.
*
* @uses add_action() https://developer.wordpress.org/reference/functions/add_action/
* @uses image_size_names_choose https://developer.wordpress.org/reference/hooks/image_size_names_choose/
*/
add_filter('image_size_names_choose', 'custom_image_sizes_in_select');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.