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
This commit is contained in:
azaozz 2009-03-08 05:42:17 +00:00
parent 519356e97a
commit 565dba7c8f
1 changed files with 17 additions and 3 deletions

View File

@ -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 = '<img src="'.attribute_escape($src).'" '.$hwstring.'class="attachment-'.attribute_escape($size).'" alt="" />';
$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("<img $hwstring");
foreach ( $attr as $name => $value ) {
$html .= " $name=" . '"' . $value . '"';
}
$html .= ' />';
}
return $html;