Make WordPress Core


Ignore:
Timestamp:
07/05/2023 07:28:02 PM (5 months ago)
Author:
flixos90
Message:

Media: Ensure custom header image tag supports loading optimization attributes.

This changeset is a follow up to [56037] and ensures that the get_header_image_tag() function receives the benefits of wp_get_loading_optimization_attributes() as well. Prior to fetchpriority support, this was not needed since the header image should never be lazy-loaded, but the image certainly is a fetchpriority candidate, so therefore it is crucial to have it supported.

Props felipeelia, spacedmonkey, mukesh27, westonruter, flixos90.
Fixes #58680.

File:
1 edited

Legend:

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

    r55977 r56142  
    12381238        $attr,
    12391239        array(
    1240             'src'    => $header->url,
    1241             'width'  => $width,
    1242             'height' => $height,
    1243             'alt'    => $alt,
     1240            'src'      => $header->url,
     1241            'width'    => $width,
     1242            'height'   => $height,
     1243            'alt'      => $alt,
     1244            'decoding' => 'async',
    12441245        )
    12451246    );
     
    12641265            }
    12651266        }
     1267    }
     1268
     1269    $attr = array_merge(
     1270        $attr,
     1271        wp_get_loading_optimization_attributes( 'img', $attr, 'get_header_image_tag' )
     1272    );
     1273
     1274    /*
     1275     * If the default value of `lazy` for the `loading` attribute is overridden
     1276     * to omit the attribute for this image, ensure it is not included.
     1277     */
     1278    if ( isset( $attr['loading'] ) && ! $attr['loading'] ) {
     1279        unset( $attr['loading'] );
     1280    }
     1281
     1282    // If the `fetchpriority` attribute is overridden and set to false or an empty string.
     1283    if ( isset( $attr['fetchpriority'] ) && ! $attr['fetchpriority'] ) {
     1284        unset( $attr['fetchpriority'] );
     1285    }
     1286
     1287    // If the `decoding` attribute is overridden and set to false or an empty string.
     1288    if ( isset( $attr['decoding'] ) && ! $attr['decoding'] ) {
     1289        unset( $attr['decoding'] );
    12661290    }
    12671291
Note: See TracChangeset for help on using the changeset viewer.