get_image_tag

The timeline below displays how wordpress function get_image_tag has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * 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.
 *
 * @since 2.5.0
 *
 * @param int          $id    Attachment ID.
 * @param string       $alt   Image description for the alt attribute.
 * @param string       $title Image description for the title attribute.
 * @param string       $align Part of the class name for aligning the image.
 * @param string|int[] $size  Optional. Image size. Accepts any registered image size name, or an array of
 *                            width and height values in pixels (in that order). Default 'medium'.
 * @return 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) . '" ' : '';
    $size_class = is_array($size) ? implode('x', $size) : $size;
    $class = 'align' . esc_attr($align) . ' size-' . esc_attr($size_class) . ' 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|int[] $size  Requested image size. Can be any registered image size name, or
     *                            an array of width and height values in pixels (in that order).
     */
    $class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
    $html = '<img src="' . esc_url($img_src) . '" alt="' . esc_attr($alt) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
    /**
     * Filters the HTML content for the image tag.
     *
     * @since 2.6.0
     *
     * @param string       $html  HTML content for the image.
     * @param int          $id    Attachment ID.
     * @param string       $alt   Image description for the alt attribute.
     * @param string       $title Image description for the title attribute.
     * @param string       $align Part of the class name for aligning the image.
     * @param string|int[] $size  Requested image size. Can be any registered image size name, or
     *                            an array of width and height values in pixels (in that order).
     */
    return apply_filters('get_image_tag', $html, $id, $alt, $title, $align, $size);
}

WordPress Version: 6.1

/**
 * 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.
 *
 * @since 2.5.0
 *
 * @param int          $id    Attachment ID.
 * @param string       $alt   Image description for the alt attribute.
 * @param string       $title Image description for the title attribute.
 * @param string       $align Part of the class name for aligning the image.
 * @param string|int[] $size  Optional. Image size. Accepts any registered image size name, or an array of
 *                            width and height values in pixels (in that order). Default 'medium'.
 * @return 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) . '" ' : '';
    $size_class = is_array($size) ? implode('x', $size) : $size;
    $class = 'align' . esc_attr($align) . ' size-' . esc_attr($size_class) . ' 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|int[] $size  Requested image size. Can be any registered image size name, or
     *                            an array of width and height values in pixels (in that order).
     */
    $class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
    $html = '<img src="' . esc_url($img_src) . '" alt="' . esc_attr($alt) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
    /**
     * Filters the HTML content for the image tag.
     *
     * @since 2.6.0
     *
     * @param string       $html  HTML content for the image.
     * @param int          $id    Attachment ID.
     * @param string       $alt   Image description for the alt attribute.
     * @param string       $title Image description for the title attribute.
     * @param string       $align Part of the class name for aligning the image.
     * @param string|int[] $size  Requested image size. Can be any registered image size name, or
     *                            an array of width and height values in pixels (in that order).
     */
    return apply_filters('get_image_tag', $html, $id, $alt, $title, $align, $size);
}

WordPress Version: 5.6

/**
 * 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.
 *
 * @since 2.5.0
 *
 * @param int          $id    Attachment ID.
 * @param string       $alt   Image description for the alt attribute.
 * @param string       $title Image description for the title attribute.
 * @param string       $align Part of the class name for aligning the image.
 * @param string|int[] $size  Optional. Image size. Accepts any registered image size name, or an array of
 *                            width and height values in pixels (in that order). Default 'medium'.
 * @return 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) . '" ' : '';
    $size_class = is_array($size) ? implode('x', $size) : $size;
    $class = 'align' . esc_attr($align) . ' size-' . esc_attr($size_class) . ' 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|int[] $size  Requested image size. Can be any registered image size name, or
     *                            an array of width and height values in pixels (in that order).
     */
    $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 . '" />';
    /**
     * Filters the HTML content for the image tag.
     *
     * @since 2.6.0
     *
     * @param string       $html  HTML content for the image.
     * @param int          $id    Attachment ID.
     * @param string       $alt   Image description for the alt attribute.
     * @param string       $title Image description for the title attribute.
     * @param string       $align Part of the class name for aligning the image.
     * @param string|int[] $size  Requested image size. Can be any registered image size name, or
     *                            an array of width and height values in pixels (in that order).
     */
    return apply_filters('get_image_tag', $html, $id, $alt, $title, $align, $size);
}

WordPress Version: 5.4

/**
 * 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.
 *
 * @since 2.5.0
 *
 * @param int          $id    Attachment ID.
 * @param string       $alt   Image description for the alt attribute.
 * @param string       $title Image description for the title attribute.
 * @param string       $align Part of the class name for aligning the image.
 * @param string|array $size  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'.
 * @return 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'.
     */
    $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 . '" />';
    /**
     * Filters the HTML content for the image tag.
     *
     * @since 2.6.0
     *
     * @param string       $html  HTML content for the image.
     * @param int          $id    Attachment ID.
     * @param string       $alt   Image description for the alt attribute.
     * @param string       $title Image description for the title attribute.
     * @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'.
     */
    return apply_filters('get_image_tag', $html, $id, $alt, $title, $align, $size);
}

WordPress Version: 4.6

/**
 * 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.
 *
 * @since 2.5.0
 *
 * @param int          $id    Attachment ID.
 * @param string       $alt   Image Description for the alt attribute.
 * @param string       $title Image Description for the title attribute.
 * @param string       $align Part of the class name for aligning the image.
 * @param string|array $size  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'.
 * @return 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'.
     */
    $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 . '" />';
    /**
     * Filters the HTML content for the image tag.
     *
     * @since 2.6.0
     *
     * @param string       $html  HTML content for the image.
     * @param int          $id    Attachment ID.
     * @param string       $alt   Alternate text.
     * @param string       $title Attachment title.
     * @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'.
     */
    return apply_filters('get_image_tag', $html, $id, $alt, $title, $align, $size);
}

WordPress Version: 4.4

/**
 * Gets an img 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.
 *
 * @since 2.5.0
 *
 * @param int          $id    Attachment ID.
 * @param string       $alt   Image Description for the alt attribute.
 * @param string       $title Image Description for the title attribute.
 * @param string       $align Part of the class name for aligning the image.
 * @param string|array $size  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'.
 * @return 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;
    /**
     * Filter 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'.
     */
    $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 . '" />';
    /**
     * Filter the HTML content for the image tag.
     *
     * @since 2.6.0
     *
     * @param string       $html  HTML content for the image.
     * @param int          $id    Attachment ID.
     * @param string       $alt   Alternate text.
     * @param string       $title Attachment title.
     * @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'.
     */
    return apply_filters('get_image_tag', $html, $id, $alt, $title, $align, $size);
}

WordPress Version: 4.3

/**
 * Gets an img 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.
 *
 * @since 2.5.0
 *
 * @param int          $id    Attachment ID.
 * @param string       $alt   Image Description for the alt attribute.
 * @param string       $title Image Description for the title attribute.
 * @param string       $align Part of the class name for aligning the image.
 * @param string|array $size  Optional. Registered image size to retrieve a tag for, or flat array
 *                            of height and width values. Default 'medium'.
 * @return 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;
    /**
     * Filter 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 $size  Optional. Default is 'medium'.
     */
    $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 . '" />';
    /**
     * Filter the HTML content for the image tag.
     *
     * @since 2.6.0
     *
     * @param string $html  HTML content for the image.
     * @param int    $id    Attachment ID.
     * @param string $alt   Alternate text.
     * @param string $title Attachment title.
     * @param string $align Part of the class name for aligning the image.
     * @param string $size  Optional. Default is 'medium'.
     */
    return apply_filters('get_image_tag', $html, $id, $alt, $title, $align, $size);
}

WordPress Version: 4.2

/**
 * Gets an img 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.
 *
 * @since 2.5.0
 *
 * @param int          $id    Attachment ID.
 * @param string       $alt   Image Description for the alt attribute.
 * @param string       $title Image Description for the title attribute.
 * @param string       $align Part of the class name for aligning the image.
 * @param string|array $size  Optional. Registered image size to retrieve a tag for, or flat array
 *                            of height and width values. Default 'medium'.
 * @return 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;
    /**
     * Filter 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 $size  Optional. Default is 'medium'.
     */
    $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 . '" />';
    /**
     * Filter the HTML content for the image tag.
     *
     * @since 2.6.0
     *
     * @param string $html  HTML content for the image.
     * @param int    $id    Attachment ID.
     * @param string $alt   Alternate text.
     * @param string $title Attachment title.
     * @param string $align Part of the class name for aligning the image.
     * @param string $size  Optional. Default is 'medium'.
     */
    $html = apply_filters('get_image_tag', $html, $id, $alt, $title, $align, $size);
    return $html;
}

WordPress Version: 3.9

/**
 * 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.
 *
 * @since 2.5.0
 *
 * @param int $id Attachment ID.
 * @param string $alt Image Description for the alt attribute.
 * @param string $title Image Description for the title attribute.
 * @param string $align Part of the class name for aligning the image.
 * @param string $size Optional. Default is 'medium'.
 * @return 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;
    /**
     * Filter 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 $size  Optional. Default is 'medium'.
     */
    $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 . '" />';
    /**
     * Filter the HTML content for the image tag.
     *
     * @since 2.6.0
     *
     * @param string $html  HTML content for the image.
     * @param int    $id    Attachment ID.
     * @param string $alt   Alternate text.
     * @param string $title Attachment title.
     * @param string $align Part of the class name for aligning the image.
     * @param string $size  Optional. Default is 'medium'.
     */
    $html = apply_filters('get_image_tag', $html, $id, $alt, $title, $align, $size);
    return $html;
}

WordPress Version: 3.7

/**
 * 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.
 *
 * @since 2.5.0
 *
 * @uses apply_filters() The 'get_image_tag_class' filter is the IMG element
 *		class attribute.
 * @uses apply_filters() The 'get_image_tag' filter is the full IMG element with
 *		all attributes.
 *
 * @param int $id Attachment ID.
 * @param string $alt Image Description for the alt attribute.
 * @param string $title Image Description for the title attribute.
 * @param string $align Part of the class name for aligning the image.
 * @param string $size Optional. Default is 'medium'.
 * @return 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;
    $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;
}