Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vanaf1979/c8a010f5e5033226b31af8d6463fe39b to your computer and use it in GitHub Desktop.
Save vanaf1979/c8a010f5e5033226b31af8d6463fe39b to your computer and use it in GitHub Desktop.
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