WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 3 years ago

#11809 closed defect (bug) (duplicate)

Galleries and template tags do not respect alternate text

Reported by: doug Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.9.1
Component: Media Keywords:
Focuses: Cc:

Description (last modified by nacin)

When adding an image directly to a post (using the media uploader), the alternate text specified by the user is used for the alt attribute of the img element. When using the [gallery] shortcode, however, the alt attribute for each image is a duplicate of the caption (post_excerpt) for that image. The alternate text supplied by the user is not used at all.


miqrogroove points out that the template tags for attachments variously output the image title or a blank attribute where the alt text should be. (Added by nacin)

Attachments (1)

fix_alt_on_image_element.patch (556 bytes) - added by doug 6 years ago.
Change alt attribute to alternate text supplied by user rather than caption

Download all attachments as: .zip

Change History (7)

@doug6 years ago

Change alt attribute to alternate text supplied by user rather than caption

comment:1 @nacin5 years ago

  • Milestone set to 3.1

comment:2 @miqrogroove5 years ago

nacin, there's a problem with this also on the gallery pages (attachment.php/image.php). The template tags for attachments variously output the image title or a blank attribute where the alt text should be. Verified on 2.9.2 and 3.0-alpha. Does that need to be a separate ticket?

comment:3 @nacin5 years ago

  • Description modified (diff)
  • Summary changed from Gallery shortcode does not respect alternate text to Galleries and template tags do not respect alternate text

Does that need to be a separate ticket?

Probably fine here.

comment:4 @nacin5 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Triage to Future Release

comment:5 @martythornley3 years ago

  • Cc marty@… added

I was testing this to look at adding a patch but it seems to have been fixed already in trunk. I couldn't find another ticket that deals with it but if you look at the wp_get_attachment_image() function, it already has the alt info added with a couple fallbacks. It adds the alt correctly to the gallery code correctly as far as I could tell.

$default_attr = array(
	'src'	=> $src,
	'class'	=> "attachment-$size",
	'alt'	=> trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first
	'title'	=> trim(strip_tags( $attachment->post_title )),
);
if ( empty($default_attr['alt']) )
	$default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption
if ( empty($default_attr['alt']) )
	$default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title

comment:6 @SergeyBiryukov3 years ago

  • Keywords needs-patch removed
  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.