From da498131069af61b7451e17e6c16aee9d295bd09 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Fri, 26 Nov 2021 22:56:02 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@52256 git-svn-id: http://core.svn.wordpress.org/trunk@51848 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/theme.php | 9 ++++++++- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 9d43d1b2a2..9737fb3cb5 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -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, ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 140c8b8d90..21cbe1e147 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52255'; +$wp_version = '5.9-alpha-52256'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.