Skip to content

Instantly share code, notes, and snippets.

@laurelstreng
Created July 24, 2022 19:08
Show Gist options
  • Save laurelstreng/8971135ccad0588cfdda68342eb78d5c to your computer and use it in GitHub Desktop.
Save laurelstreng/8971135ccad0588cfdda68342eb78d5c to your computer and use it in GitHub Desktop.
WordPress: Enabling custom image sizes for WordPress post content/blocks
// Add a custom image size to your theme, the usage is limited only to your theme
add_image_size( 'sidebar-thumb', 120, 120, true ); // Hard Crop Mode
add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop Mode
add_image_size( 'singlepost-thumb', 590, 9999 ); // Unlimited Height Mode
add_image_size( ‘slide-thumb’, 256, 148, true, array( ‘center’, ‘center’ ) ); // Cropped Center
// Make the custom image sizes available for the post author to use within the post content/blocks
function lstreng_custom_image_sizes( $size_names ) {
$new_sizes = array(
'homepage-thumb' => 'Homepage Thumbmail',
'singlepost-thumb' => 'Infographic Single Post'
);
return array_merge( $size_names, $new_sizes );
}
add_filter( 'image_size_names_choose', 'lstreng_custom_image_sizes' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment