From 044eb3afba1b7ed5ce7da02fa335a6ea4893418a Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sun, 18 Apr 2010 08:52:18 +0000 Subject: [PATCH] Use Alt Text for Image alt caption (Falling back to Caption, and finally title) in wp_get_attachment_image() and subsequently, WordPress Galleries. Props kallewangstedt for initial patch. Fixes #11846 git-svn-id: https://develop.svn.wordpress.org/trunk@14145 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/media.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 49950b19ba..70f6af5122 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -609,9 +609,14 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa $default_attr = array( 'src' => $src, 'class' => "attachment-$size", - 'alt' => trim(strip_tags( $attachment->post_excerpt )), + '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 + $attr = wp_parse_args($attr, $default_attr); $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment ); $attr = array_map( 'esc_attr', $attr );