Make WordPress Core


Ignore:
Timestamp:
06/09/2022 05:29:57 AM (2 years ago)
Author:
peterwilsoncc
Message:

Media: Add decoding="async" to image attributes.

Dynamically add decoding="async" to image tags on the front end of a site to instruct browsers to download them in parallel.

Modifies wp_get_attachment_image(), get_avatar() to include the attribute by default. Modifies wp_filter_content_tags() to add the attribute during the front-end render of the site.

Introduces wp_img_tag_add_decoding_attr() to take an image tag and modify it to include the attribute. Introduces the filter wp_img_tag_add_decoding_attr used to define the default value for the attribute.

Props adamsilverstein, ayeshrajans, costdev, flixos90, hellofromtonya, isaumya, michaelbourne, mihai2u, mitogh, sergiomdgomes, spacedmonkey, westonruter, peterwilsoncc.
Fixes #53232.

File:
1 edited

Legend:

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

    r53473 r53480  
    27652765            'loading'       => null,
    27662766            'extra_attr'    => '',
     2767            'decoding'      => 'async',
    27672768        );
    27682769
     
    28502851
    28512852            $extra_attr .= "loading='{$loading}'";
     2853        }
     2854
     2855        if ( in_array( $args['decoding'], array( 'async', 'sync', 'auto' ) ) && ! preg_match( '/\bdecoding\s*=/', $extra_attr ) ) {
     2856            if ( ! empty( $extra_attr ) ) {
     2857                $extra_attr .= ' ';
     2858            }
     2859            $extra_attr .= "decoding='{$args['decoding']}'";
    28522860        }
    28532861
Note: See TracChangeset for help on using the changeset viewer.