From 565dba7c8f99f4d8297e56414eed1b45b3a303ce Mon Sep 17 00:00:00 2001 From: azaozz Date: Sun, 8 Mar 2009 05:42:17 +0000 Subject: [PATCH] Add alt text and filter to wp_get_attachment_image(), props Sam_a, fixes #8732 git-svn-id: http://svn.automattic.com/wordpress/trunk@10744 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 342da6beb..20af85f7b 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -514,9 +514,10 @@ function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = } /** - * Retrieve img HTML content for an image to represent an attachment. + * Get an HTML img element representing an image attachment * - * @see wp_get_attachment_image_src() Returns img HTML element based on array. + * @uses apply_filters() Calls 'wp_get_attachment_image_attributes' hook on attributes array + * @uses wp_get_attachment_image_src() Gets attachment file URL and dimensions * @since 2.5.0 * * @param int $attachment_id Image attachment ID. @@ -533,7 +534,20 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa $hwstring = image_hwstring($width, $height); if ( is_array($size) ) $size = join('x', $size); - $html = ''; + $attachment =& get_post($attachment_id); + $attr = array( + 'src' => $src, + 'class' => "attachment-$size", + 'alt' => trim(strip_tags( $attachment->post_excerpt )), + 'title' => trim(strip_tags( $attachment->post_title )), + ); + $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment ); + $attr = array_map( 'attribute_escape', $attr ); + $html = rtrim(" $value ) { + $html .= " $name=" . '"' . $value . '"'; + } + $html .= ' />'; } return $html;