Accessibility: Themes: Use a default empty alt attribute for the non-linked custom logo on the home page.

After [48039] it became clear that the non-linked custom logo on the home page needs an empty alt attribute, as in most of the cases the logo is decorative and doesn't need its purpose to be described.

This change outputs an empty alt attribute by default for the custom logo on the home page. If necessary, it is possible to use the new 'get_custom_logo_image_attributes' filter to manipulate the default attributes for the logo image and set an alt attribute.

Props FlorianBrinkmann, Soean, sabernhardt, audrasjb, SergeyBiryukov, samful, knutsp.
See #36640.
Fixes #37011.

Built from https://develop.svn.wordpress.org/trunk@48283


git-svn-id: http://core.svn.wordpress.org/trunk@48052 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrea Fercia 2020-07-03 12:58:07 +00:00
parent 69e876747d
commit 83c7b67c32
2 changed files with 16 additions and 8 deletions

View File

@ -981,13 +981,21 @@ function get_custom_logo( $blog_id = 0 ) {
'class' => 'custom-logo',
);
/*
* If the logo alt attribute is empty, get the site title and explicitly pass it
* to the attributes used by wp_get_attachment_image().
*/
$image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
if ( empty( $image_alt ) ) {
$custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
if ( is_front_page() ) {
/*
* If on the home page, set the logo alt attribute to an empty string,
* as the image is decorative and doesn't need its purpose to be described.
*/
$custom_logo_attr['alt'] = '';
} else {
/*
* If the logo alt attribute is empty, get the site title and explicitly pass it
* to the attributes used by wp_get_attachment_image().
*/
$image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
if ( empty( $image_alt ) ) {
$custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
}
}
/**

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-alpha-48282';
$wp_version = '5.5-alpha-48283';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.