From 88c91eeaa6ab8d73bb3f5b301f9a0faf41e8e3e2 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Fri, 3 Jul 2020 12:56:43 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@48283 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/general-template.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 46e585df12..eafd26717a 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -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' ); + } } /**