Gets an img tag for an image attachment, scaling it down if requested.

The {@see ‘get_image_tag_class’} filter 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, {@see ‘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.


get_image_tag( $id, $alt, $title, $align, $size = 'medium' )
 (int) Attachment ID.
 (string) Image Description for the alt attribute.
 (string) Image Description for the title attribute.
 (string) Part of the class name for aligning the image.
 (string|array) Optional. Registered image size to retrieve a tag for. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default 'medium'.
Default: 'medium'


(string) HTML IMG element for given image attachment


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;

	 * Filters the value of the attachment's image tag class attribute.
	 * @since 2.6.0
	 * @param string       $class CSS class name or space-separated list of classes.
	 * @param int          $id    Attachment ID.
	 * @param string       $align Part of the class name for aligning the image.
	 * @param string|array $size  Size of image. Image size or array of width and height values (in that order).
	 *                            Default 'medium'.
19 more lines...
WP Trac GitHub

Link here