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. @type string $src Image attachment URL. @type string $class CSS class name or space-separated list of classes. Default `attachment-$size_class size-$size_class`, where `$size_class` is the image size being requested. @type string $alt Image description for the alt attribute. @type string $srcset The 'srcset' attribute value. @type string $sizes The 'sizes' attribute value. }
  • (string) HTML img element or empty string on failure.
Defined at:


Get an HTML img element representing an image attachmentWhile `$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_src, wp_get_attachment_image_url, wp_get_attachment_image_sizes, wp_get_attachment_image_srcset, wp_attachment_is_image

Top Google Results

User discussions

wpseek mobile