function get_image_tag($id, $alt, $title, $align, $size='medium') {}

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.


  • int $id: Attachment ID.
  • string $alt: Image Description for the alt attribute.
  • string $title: Image Description for the title attribute.
  • string $align: Part of the class name for aligning the image.
  • string $size: Optional. Default is ‘medium’.

Return values

returns:HTML IMG element for given image attachment

Defined filters

  • get_image_tag_class
    apply_filters('get_image_tag_class', $class, $id, $align, $size)
  • get_image_tag
    apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size )

Source code

function get_image_tag($id, $alt, $title, $align, $size='medium') {

	list( $img_src, $width, $height ) = image_downsize($id, $size);

	$hwstring = image_hwstring($width, $height);

	$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="' . esc_attr($title).'" '.$hwstring.'class="'.$class.'" />';

	$html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );

	return $html;



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: