WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#39813 closed enhancement (duplicate)

Add_Image_Size: Extra Parameter - Limit thumbnail-size generation to custom post type

Reported by: tifosi Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.2
Component: Media Keywords:
Focuses: Cc:
PR Number:

Description

I noticed a thread on the forum which itched a frustration I increasingly have with image handling in WordPress, particularly after v3. I couldn't see any related TRAC enhancement request.

https://wordpress.org/ideas/topic/limit-thumbnail-size-generation-to-custom-post-type/

For complex CMS-style sites that have extensive usage of custom post types, taxonomies, and meta data - using the increasingly available plugins like ACF for image meta, it is quite often that a site will register multiple calls to add_image_size to provide all the template layouts required.

Herein lies the problem: add_image_size is agnostic to the image size and simply iterates through the registered intermediate image sizes to generate an image for each size, irrespective of whether it's ever needed, or will be used.

Add on the generic Wordpress sizes: thumbnail, medium, large etc and you have a recipe for a file system full to the brim with useless images.

It would be extremely useful for the function to have:

  1. An additional parameter to restrict the post_type usage via the intermediate_sizes global probably, so that dynamic image generation has some direction.
  2. A filter to restrict the image generation, e.g add_{post_type}_image_size:
    add_filter( 'add_event_image_size', function( $sizes ) { return ['event_thumbnail', 'event_category' ]; }, 10,1);
    

Thinking out loud on that one, depends on the codebase.

  1. Both.

Really hope that when the current 4.7-4.8 focus on the WP-API is completed that a new focus on media handling is looked at. This is a feature requested by many, and needed for a while.

Noted enhancements: #35775, #15311

Thanks

Change History (1)

#1 @swissspidy
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Thanks for your report. We're already tracking this enhancement in #13372. Feel free to leave feedback there.

Note: See TracTickets for help on using tickets.