Media: Allow setting custom image alt text in custom header image.

This change applies the alternative text assigned to the custom header image, if available. Otherwise, it leaves it empty. It fixes an issue where the alternative text was always the site title, which is not relevant in most use cases.

Props webmandesign, mukesh27, afercia, anevins, mikeschroder, nrqsnchz, audrasjb, sabernhardt, joedolson, Boniu91.
Fixes #46124.


git-svn-id: https://develop.svn.wordpress.org/trunk@52256 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras 2021-11-26 22:54:10 +00:00
parent 7b9e33a1e7
commit a9e8641a2b

View File

@ -1194,13 +1194,20 @@ function get_header_image_tag( $attr = array() ) {
$width = absint( $header->width );
$height = absint( $header->height );
// Use alternative text assigned to the image, if available. Otherwise, leave it empty.
if ( ! empty( $header->attachment_id ) && is_string( get_post_meta( $header->attachment_id, '_wp_attachment_image_alt', true ) ) ) {
$alt = get_post_meta( $header->attachment_id, '_wp_attachment_image_alt', true );
} else {
$alt = '';
}
$attr = wp_parse_args(
$attr,
array(
'src' => $header->url,
'width' => $width,
'height' => $height,
'alt' => get_bloginfo( 'name' ),
'alt' => $alt,
)
);