Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get image tag


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.

You'll need to manually supply the alt and title tags - to avoid having to do this, use wp_get_image_attachment instead.


<?php get_image_tag$id$alt$title$align$size ); ?>


(int) (required) Attachment ID.
Default: None
(string) (required) Image Description for the alt attribute.
Default: None
(string) (required) Image Description for the title attribute.
Default: None
(string) (required) Part of the class name for aligning the image.
Default: None
(string) (optional) Optional. Default is 'medium'.
Default: medium

Return Values

HTML IMG element for given image attachment

Change Log

Since: 2.5

Source File

get_image_tag() is located in wp-includes/media.php


Attachment Functions:

get_children(), get attached media(), the_attachment_link(), get_attachment_link(), wp_get_attachment_link(), wp_get_attachment_image(), wp_get_attachment_image_src(), wp_get_attachment_url(), wp_get_attachment_thumb_file(), wp_get_attachment_thumb_url(), is_attachment(), wp_get_attachment_metadata()