Last active
January 2, 2020 13:03
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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