WordPress.org

Make WordPress Core

Changeset 48283


Ignore:
Timestamp:
07/03/2020 12:56:43 PM (5 months ago)
Author:
afercia
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r48277 r48283  
    982982        );
    983983
    984         /*
    985          * If the logo alt attribute is empty, get the site title and explicitly pass it
    986          * to the attributes used by wp_get_attachment_image().
    987          */
    988         $image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
    989         if ( empty( $image_alt ) ) {
    990             $custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
     984        if ( is_front_page() ) {
     985            /*
     986             * If on the home page, set the logo alt attribute to an empty string,
     987             * as the image is decorative and doesn't need its purpose to be described.
     988             */
     989            $custom_logo_attr['alt'] = '';
     990        } else {
     991            /*
     992             * If the logo alt attribute is empty, get the site title and explicitly pass it
     993             * to the attributes used by wp_get_attachment_image().
     994             */
     995            $image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
     996            if ( empty( $image_alt ) ) {
     997                $custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
     998            }
    991999        }
    9921000
Note: See TracChangeset for help on using the changeset viewer.