mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@56142 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1237,10 +1237,11 @@ function get_header_image_tag( $attr = array() ) {
|
||||
$attr = wp_parse_args(
|
||||
$attr,
|
||||
array(
|
||||
'src' => $header->url,
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'alt' => $alt,
|
||||
'src' => $header->url,
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'alt' => $alt,
|
||||
'decoding' => 'async',
|
||||
)
|
||||
);
|
||||
|
||||
@@ -1265,6 +1266,29 @@ function get_header_image_tag( $attr = array() ) {
|
||||
}
|
||||
}
|
||||
|
||||
$attr = array_merge(
|
||||
$attr,
|
||||
wp_get_loading_optimization_attributes( 'img', $attr, 'get_header_image_tag' )
|
||||
);
|
||||
|
||||
/*
|
||||
* 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 ( isset( $attr['loading'] ) && ! $attr['loading'] ) {
|
||||
unset( $attr['loading'] );
|
||||
}
|
||||
|
||||
// If the `fetchpriority` attribute is overridden and set to false or an empty string.
|
||||
if ( isset( $attr['fetchpriority'] ) && ! $attr['fetchpriority'] ) {
|
||||
unset( $attr['fetchpriority'] );
|
||||
}
|
||||
|
||||
// If the `decoding` attribute is overridden and set to false or an empty string.
|
||||
if ( isset( $attr['decoding'] ) && ! $attr['decoding'] ) {
|
||||
unset( $attr['decoding'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the list of header image attributes.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user