Make WordPress Core

Opened 21 months ago

Last modified 17 months ago

#56056 new enhancement

Specify a Custom Array of $sizes for `wp_get_attachment_image` to Reduce HTML Bloat

Reported by: xmic's profile xmic Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Post Thumbnails Keywords: needs-patch
Focuses: performance Cc:

Description

Plugins and the theme can specify multiple thumbnail sizes. Using wp_get_attachment_image provides a modern solution to responsive image sizes, however, it does not currently account for reducing the bloat to all the registered thumbnail sizes that are added by plugins / theme.

Therefore a proposal is to allow a custom list of thumbnails to use, this can, for example, be specified as:

<?php
wp_get_attachment_image(123, [['thumbnail', [1200, 630], 'medium', 'large'], true]);

Where the true is to identify that we want to enable a specified list of thumbnail sizes, and not use all of the thumbnail sizes registered.

It will only loop through the specified $sizes that were mentioned in the $sizes parameter.

HTML document size is a large factor in determining if a website is to be bloated or not. Therefore it would be beneficial to allow developers to specify specific thumbnail sizes that are to be used for what it is intended for.

Kind regards,
Michael

Change History (1)

#1 @desrosj
17 months ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.