Skip to content

Instantly share code, notes, and snippets.

@askwpgirl
Last active February 6, 2024 04:52
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 askwpgirl/aaf19bf9c99162741a3b6bbf6698b2c3 to your computer and use it in GitHub Desktop.
Save askwpgirl/aaf19bf9c99162741a3b6bbf6698b2c3 to your computer and use it in GitHub Desktop.
Add New WordPress Image Sizes
<?php
// See https://developer.wordpress.org/reference/functions/add_image_size/ for reference.
// Also https://bloggerpilot.com/en/disable-wordpress-image-sizes/
// Note: You must regenerate thumbnails for new image sizes to be generated. Use Rengenerate Thumbnails plugin.
// Copy the code below into a new snippet using Code Snippets plugin
// Add all new image sizes for the site here, examples:
add_image_size( 'grid-rectangle', 640, 420, true );
add_image_size( 'logo-rectangle', 400, 250, true );
// This adds the images sizes above to WordPress interfaces so you can choose them:
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'grid-rectangle' => __( 'Grid Rectangle' ),
'logo-rectangle' => __( 'Logo Rectangle' ),
) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment