Skip to content

Instantly share code, notes, and snippets.

@ajitbohra
Last active May 30, 2017 15:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajitbohra/5117645476bab3fe4bdc to your computer and use it in GitHub Desktop.
Save ajitbohra/5117645476bab3fe4bdc to your computer and use it in GitHub Desktop.
Wordpress Adding image size
<?php
add_image_size( 'custom-size', 220, 180 ); // 220 pixels wide by 180 pixels tall, soft proportional crop mode
add_image_size( 'custom-size', 220, 180, true ); // 220 pixels wide by 180 pixels tall, hard crop mode
add_image_size( 'custom-size', 220, 220, array( 'left', 'top' ) ); // Hard crop left top
/*
For Media Library Images (Admin):
--------------------------------
You can also make your custom sizes selectable from your WordPress admin.
To do so, you have to use the image_size_names_choose hook to assign them a normal, human-readable name…
*/
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'your-custom-size' => __( 'Your Custom Size Name' ),
) );
}
?>
@artmaug
Copy link

artmaug commented May 30, 2017

Thanks a lot!

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