Opened 3 years ago
Closed 10 months ago
#11809 closed defect (bug) (duplicate)
Galleries and template tags do not respect alternate text
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Media | Version: | 2.9.1 |
| Severity: | normal | Keywords: | |
| Cc: | marty@… |
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)
Change History (7)
comment:2
miqrogroove — 3 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?
- 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.
- Keywords needs-patch added
- Milestone changed from Awaiting Triage to Future Release
comment:5
martythornley — 10 months 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
SergeyBiryukov — 10 months ago
- Keywords needs-patch removed
- Milestone Future Release deleted
- Resolution set to duplicate
- Status changed from new to closed

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