1

Would it be possible to be able to select the image sizes you want to be uploaded when you upload an image?

E.g., I have these image sizes:

    // Set Media Sizes
    set_post_thumbnail_size( 864, 486, true ); // 864 pixels wide by 486 pixels tall, crop from the center
    add_image_size( 'klein', 300, 169, true); // 300 pixels wide by 169 pixels tall, crop from the center
    add_image_size( 'smartphone', 640, 360, true); // 640 pixels wide by 360 pixels tall, crop from the center
    add_image_size( 'thumbnail-normal', 864, 9999); // 864 pixels wide and unlimited height
    add_image_size( 'database-thumbnail-small', 640, 117, true); // 640 pixels wide by 117 pixels tall, crop from the center
    add_image_size( 'database-thumbnail-normal', 1366, 249, true); // 1366 pixels wide by 768 pixels tall, crop from the center
    add_image_size( 'database-thumbnail-big', 1920, 350, true ); // 1920 pixels wide by 350 pixels tall, crop from the center

When I upload an image in the Media Uploader I would like to be able to select the image sizes I want that image to be actally uploaded in. Since I don't need all image sizes for every image, but I do need to use every image size on my website. And this will take up a lot af unnecessary space.

1

If I am not mistaken, WordPress just creates these sizes. The only thing you can say is which image you want to pick of these sizes. You can use this piece of code to make the sizes appear inside of the dropdown. Make sure to place this inside the functions.php after adding the image_sizes.

function my_custom_sizes( $sizes ) {
    return array_merge( $sizes, array(
      'home-hero-s' => __( 'home-hero-s' )
    ) );
  }
  add_filter( 'image_size_names_choose', 'my_custom_sizes' );

Where you see 'home-hero-s' that is the name of your custom image size and the next ( 'home-hero-s' ) is the name you give it to show in the dropdown of the size selector. I don't know any function that helps with selecting the size you want to upload. So I hope this helps you.

1
add_filter( 'intermediate_image_sizes', 'AS_cpt_image_sizes', 999 );
function AS_cpt_image_sizes( $image_sizes ){

// size for your custom post type
$cpt_sizes = array( 'klein', 'smartphone' ); 

if( isset($_REQUEST['post_id']) && 'your_cpt' === get_post_type( $_REQUEST['post_id'] ) )
    return $cpt_sizes;

return $image_sizes;}

This should work if you need specific image sizes for specific custom post types, from the "upload media" of the edit-post screen

  • Thank you, but it's not quite what I wanted. It's a step in the right direction though, so thanks! – Stef May 26 '18 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.