Created
November 8, 2020 09:15
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simpler method if you don't care about the order of options: https://gist.github.com/blogjunkie/c220b4f50b06a5d52bb4f2f4cb477908