mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-08 22:54:36 +00:00
Media: Allow to omit decoding="async" on tags from wp_get_attachment_image().
When adding `decoding="async"` to images was introduced in [53480], it did not provide the ability to customize that behavior specifically for image tags returned from `wp_get_attachment_image()`. With this changeset it is now possible to explicitly provide a `decoding` value of e.g. boolean `false` in the `$attr` parameter of the function, to ensure the attribute is omitted. Props maximej, adamsilverstein, flixos90, costdev, peterwilsoncc, mukesh27. Fixes #57086. git-svn-id: https://develop.svn.wordpress.org/trunk@55171 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1023,7 +1023,8 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
|
||||
* will result in the attribute being omitted for the image.
|
||||
* Defaults to 'lazy', depending on wp_lazy_loading_enabled().
|
||||
* @type string $decoding The 'decoding' attribute value. Possible values are
|
||||
* 'async' (default), 'sync', or 'auto'.
|
||||
* 'async' (default), 'sync', or 'auto'. Passing false or an empty
|
||||
* string will result in the attribute being omitted.
|
||||
* }
|
||||
* @return string HTML img element or empty string on failure.
|
||||
*/
|
||||
@@ -1056,6 +1057,11 @@ function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f
|
||||
|
||||
$attr = wp_parse_args( $attr, $default_attr );
|
||||
|
||||
// Omit the `decoding` attribute if the value is invalid according to the spec.
|
||||
if ( empty( $attr['decoding'] ) || ! in_array( $attr['decoding'], array( 'async', 'sync', 'auto' ), true ) ) {
|
||||
unset( $attr['decoding'] );
|
||||
}
|
||||
|
||||
// If the default value of `lazy` for the `loading` attribute is overridden
|
||||
// to omit the attribute for this image, ensure it is not included.
|
||||
if ( array_key_exists( 'loading', $attr ) && ! $attr['loading'] ) {
|
||||
|
||||
Reference in New Issue
Block a user