1095 | | // Generate 'srcset' and 'sizes' if not already present. |
1096 | | if ( empty( $attr['srcset'] ) && ! empty( $header->attachment_id ) ) { |
1097 | | $image_meta = get_post_meta( $header->attachment_id, '_wp_attachment_metadata', true ); |
1098 | | $size_array = array( $width, $height ); |
| 1095 | if ( ! empty( $header->attachment_id ) ) { |
| 1096 | // Use actual alt attribute text from the image, if set. |
| 1097 | // The image URL can be filtered via `get_header_image()` above, so we need to check it before applying the alt text. |
| 1098 | $image_alt = get_post_meta( $header->attachment_id, '_wp_attachment_image_alt', true ); |
| 1099 | if ( ! empty( $image_alt ) && wp_get_attachment_url( $header->attachment_id ) === $attr['src'] ) { |
| 1100 | $attr['alt'] = $image_alt; |
| 1101 | } |
1100 | | if ( is_array( $image_meta ) ) { |
1101 | | $srcset = wp_calculate_image_srcset( $size_array, $header->url, $image_meta, $header->attachment_id ); |
1102 | | $sizes = ! empty( $attr['sizes'] ) ? $attr['sizes'] : wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id ); |
| 1103 | // Generate 'srcset' and 'sizes' if not already present. |
| 1104 | if ( empty( $attr['srcset'] ) ) { |
| 1105 | $image_meta = get_post_meta( $header->attachment_id, '_wp_attachment_metadata', true ); |
| 1106 | $size_array = array( $width, $height ); |
1104 | | if ( $srcset && $sizes ) { |
1105 | | $attr['srcset'] = $srcset; |
1106 | | $attr['sizes'] = $sizes; |
| 1108 | if ( is_array( $image_meta ) ) { |
| 1109 | $srcset = wp_calculate_image_srcset( $size_array, $header->url, $image_meta, $header->attachment_id ); |
| 1110 | $sizes = ! empty( $attr['sizes'] ) ? $attr['sizes'] : wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id ); |
| 1111 | |
| 1112 | if ( $srcset && $sizes ) { |
| 1113 | $attr['srcset'] = $srcset; |
| 1114 | $attr['sizes'] = $sizes; |
| 1115 | } |