WordPress: Add custom image thumbnail sizes to the media library’s insert size choices
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<br/>/** * Add intermediate image sizes to media gallery modal dialog */ function nf_add_image_sizes_to_editor( $form_fields, $post ) { if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) return $form_fields; if ( is_array($imagedata['sizes']) ) { foreach ( $imagedata['sizes'] as $size => $val ) { if ( $size == 'teaser-image' ) {<span> </span>// put your thumbnail image name(s) here $css_id = "image-size-{$size}-{$post->ID}"; $pretty_size = ucwords(str_replace('-', ' ' , $size)); $html .= ''; $html .= ''.$pretty_size.''; $html .= ' '.sprintf( __("(%d × %d)"), $val['width'], $val['height'] ). ''; $html .= ''; } } } $form_fields['image-size']['html'] .= $html; return $form_fields; } add_filter( 'attachment_fields_to_edit', 'nf_add_image_sizes_to_editor', 100, 2 ); |


