An <img src /> tag for an image attachment, scaling it down if requested.
The filter ‘get_image_tag_class’ allows for changing the class name for the image without having to use regular expressions on the HTML content. The parameters are: what WordPress will use for the class, the Attachment ID, image align value, and the size the image should be.
The second filter ‘get_image_tag’ has the HTML content, which can then be further manipulated by a plugin to change all attribute values and even HTML content.
Signature
get_image_tag( $id, $alt, $title, $align, $size = 'medium' )
- id
- (int) Attachment ID.
- alt
- (string) Image Description for the alt attribute.
- title
- (string) Image Description for the title attribute.
- align
- (string) Part of the class name for aligning the image.
- size
- (string) Optional. Default is 'medium'.
Default:'medium'
Return
(string) HTML IMG element for given image attachment
Source
function get_image_tag($id, $alt, $title, $align, $size='medium') {
list( $img_src, $width, $height ) = image_downsize($id, $size);
$hwstring = image_hwstring($width, $height);
$title = $title ? 'title="' . esc_attr( $title ) . '" ' : '';
$class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;
$class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
$html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
$html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
return $html;
}
WP Trac GitHub Bitbucket
Link here
-
URL
http://queryposts.com/function/get_image_tag/ -
HTML
<a href='http://queryposts.com/function/get_image_tag/'>get_image_tag()</a> -
Markdown
[get_image_tag()](http://queryposts.com/function/get_image_tag/) -
BBCode
[url=http://queryposts.com/function/get_image_tag/]get_image_tag()[/url]