Last active
March 5, 2018 00:26
-
-
Save ivanhoe011/25fb8e27420b4fffeeb1 to your computer and use it in GitHub Desktop.
Add custom thumb sizes to Wordpress media dialog
This file contains 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 | |
// From http://wordpress.stackexchange.com/questions/76209/custom-image-size-with-new-media-manager-in-wordpress-3-5 | |
/* | |
* Add custom thumb sizes to Wordpress media dialog | |
*/ | |
function my_insert_custom_image_sizes( $sizes ) { | |
// get the custom image sizes | |
global $_wp_additional_image_sizes; | |
// if there are none, just return the built-in sizes | |
if ( empty( $_wp_additional_image_sizes ) ) | |
return $sizes; | |
// add all the custom sizes to the built-in sizes | |
foreach ( $_wp_additional_image_sizes as $id => $data ) { | |
// take the size ID (e.g., 'my-name'), replace hyphens with spaces, | |
// and capitalise the first letter of each word | |
if ( !isset($sizes[$id]) ) | |
$sizes[$id] = ucfirst( str_replace( '-', ' ', $id ) ); | |
} | |
return $sizes; | |
} | |
function custom_image_setup () { | |
add_theme_support( 'post-thumbnails' ); | |
add_image_size( 'custom-image-size-1', 160, 9999 ); // small columned | |
add_image_size( 'custom-image-size-2', 300, 9999 ); // medium | |
add_image_size( 'custom-image-size-3', 578, 190, true ); // cropped | |
add_filter( 'image_size_names_choose', 'my_insert_custom_image_sizes' ); | |
} | |
add_action( 'after_setup_theme', 'custom_image_setup' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment