Created
September 21, 2022 03:28
-
-
Save wpgaurav/a3ee5565dadc1d49edfe4a519b78203c to your computer and use it in GitHub Desktop.
Support for Post Thumbnails & Custom Thumbnail Sizes in WordPress and Add those sizes to Block Editor/Gutenberg
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 | |
add_action( 'init', function() { | |
add_image_size( 'rename-this', 1200, 500, false ); | |
add_image_size( 'rename-again', 550, 550, true ); | |
} ); | |
// Add these sizes to Gutenberg | |
add_filter( 'image_size_names_choose','md_custom_image_sizes_gb' ); | |
function md_custom_image_sizes_gb( $sizes ) { | |
return array_merge( $sizes, array( | |
//Add your custom sizes here | |
'rename-this' => __( 'Banner' ), | |
'rename-again' => __( 'Block' ) | |
) | |
); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
‘true’ and ‘false’ are answers of argument, whether to force-crop the image or not.