Make WordPress Core


Ignore:
Timestamp:
01/31/2023 07:39:51 PM (4 years ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r54802 r55171  
    10241024 *                                  Defaults to 'lazy', depending on wp_lazy_loading_enabled().
    10251025 *     @type string       $decoding The 'decoding' attribute value. Possible values are
    1026  *                                  'async' (default), 'sync', or 'auto'.
     1026 *                                  'async' (default), 'sync', or 'auto'. Passing false or an empty
     1027 *                                  string will result in the attribute being omitted.
    10271028 * }
    10281029 * @return string HTML img element or empty string on failure.
    … …  
    10561057
    10571058                $attr = wp_parse_args( $attr, $default_attr );
     1059
     1060                // Omit the `decoding` attribute if the value is invalid according to the spec.
     1061                if ( empty( $attr['decoding'] ) || ! in_array( $attr['decoding'], array( 'async', 'sync', 'auto' ), true ) ) {
     1062                        unset( $attr['decoding'] );
     1063                }
    10581064
    10591065                // If the default value of `lazy` for the `loading` attribute is overridden
Note: See TracChangeset for help on using the changeset viewer.