WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/19/2016 03:05:51 AM (3 years ago)
Author:
joemcgill
Message:

Media: Remove alt fallbacks to improve accessibility.

This removes the fallbacks in wp_get_attachment_image() and in
wp.media.string.props which attempt to generate an alt value
from the image caption or title if an alt attribute isn't explicitly
set.

This allows for image HTML to be generated that contains an empty alt
value, i.e., alt="" which is much preferable for screen readers than
reading redundant content in the case of a caption, or when reading the
image title, which is often generated from the filename and not helpful
as alt text.

Props odie2, joedolson, rianrietveld, afercia, iamjolly, joemcgill.
Fixes #34635.

File:
1 edited

Legend:

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

    r38795 r38812  
    867867            'src'   => $src,
    868868            'class' => "attachment-$size_class size-$size_class",
    869             'alt'   => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first
     869            'alt'   => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),
    870870        );
    871         if ( empty($default_attr['alt']) )
    872             $default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption
    873         if ( empty($default_attr['alt']) )
    874             $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title
    875871
    876872        $attr = wp_parse_args( $attr, $default_attr );
Note: See TracChangeset for help on using the changeset viewer.