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 );