Skip to content

Instantly share code, notes, and snippets.

@blogjunkie
Created November 8, 2020 09:15
Show Gist options
  • Save blogjunkie/3f0430e5759be249c6c0966daac19c18 to your computer and use it in GitHub Desktop.
Save blogjunkie/3f0430e5759be249c6c0966daac19c18 to your computer and use it in GitHub Desktop.
Register a new image size, then make it selectable in Image Size options
<?php // Do not copy this line
/**
* Register a "Wide" image size and add it to the Image Size options
* after "Large" i.e. Thumnail, Medium, Large, Wide, Full Size
* to correspond with Align Wide and Align Full alignments
*/
// Add a new "Wide" image size
add_image_size( 'wide', 1200, 0 );
// Make it selectable in the Image Size options
add_filter( 'image_size_names_choose', 'custom_sizes_choose' );
function custom_sizes_choose( $sizes ) {
$new_sizes = [];
// Add new size after 'Large'
foreach( $sizes as $name => $label ) {
$new_sizes[ $name ] = $label;
if ( 'large' == $name ) {
$new_sizes['wide'] = __( 'Wide', 'textdomain' );
}
}
return $new_sizes;
}
@blogjunkie
Copy link
Author

Simpler method if you don't care about the order of options: https://gist.github.com/blogjunkie/c220b4f50b06a5d52bb4f2f4cb477908

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