Skip to content

Instantly share code, notes, and snippets.

@wpgaurav
Created September 21, 2022 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpgaurav/a3ee5565dadc1d49edfe4a519b78203c to your computer and use it in GitHub Desktop.
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
<?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' )
)
);
}
?>
@wpgaurav
Copy link
Author

‘true’ and ‘false’ are answers of argument, whether to force-crop the image or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment