Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Array of custom image sizes to add
- $my_image_sizes = array(
- array( 'name'=>'slideshow-full', 'width'=>544, 'height'=>380, 'crop'=>true ),
- array( 'name'=>'slideshow-thumb', 'width'=>30, 'height'=>30, 'crop'=>true ),
- array( 'name'=>'attraction-thumb', 'width'=>67, 'height'=>67, 'crop'=>false ),
- );
- // For each new image size, run add_image_size() and update_option() to add the necessary info.
- // update_option() is good because it only updates the database if the value has changed. It also adds the option if it doesn't exist
- foreach ( $my_image_sizes as $my_image_size ){
- add_image_size( $my_image_size['name'], $my_image_size['width'], $my_image_size['height'], $my_image_size['crop'] );
- update_option( $my_image_size['name']."_size_w", $my_image_size['width'] );
- update_option( $my_image_size['name']."_size_h", $my_image_size['height'] );
- update_option( $my_image_size['name']."_crop", $my_image_size['crop'] );
- }
- // Hook into the 'intermediate_image_sizes' filter used by image-edit.php.
- // This adds the custom sizes into the array of sizes it uses when editing/saving images.
- add_filter( 'intermediate_image_sizes', 'my_add_image_sizes' );
- function my_add_image_sizes( $sizes ){
- global $my_image_sizes;
- foreach ( $my_image_sizes as $my_image_size ){
- $sizes[] = $my_image_size['name'];
- }
- return $sizes;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement