wp_get_attachment_image ( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' )

  • (int) $attachment_id Image attachment ID.
  • (string|array) $size Optional. Image size. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default 'thumbnail'.
  • (bool) $icon Optional. Whether the image should be treated as an icon. Default false.
  • (string|array) $attr Optional. Attributes for the image markup. Default empty.
  • (string) HTML img element or empty string on failure.
Defined at:


Get an HTML img element representing an image attachment

While $size will accept an array, it is better to register a size with add_image_size() so that a cropped version is generated. It's much more efficient than having to find the closest-sized image and then having the browser scale down the image.

Related Functions

wp_get_attachment_image_url, wp_get_attachment_image_src, wp_get_attachment_image_sizes, wp_get_attachment_image_srcset, wp_attachment_is_image

Top Google Results

User discussions

wpseek mobile