From 3eec9dd73fb7b6a7d576e67e374175a420f9dd5c Mon Sep 17 00:00:00 2001 From: dd32 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: http://svn.automattic.com/wordpress/trunk@14145 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- 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 49950b19b..70f6af512 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 );