wp_get_attachment_image( int $attachment_id, string|array $size = 'thumbnail', bool $icon = false, string|array $attr = '' )

Get an HTML img element representing an image attachment

21 related functions found for: wp_get_attachment_image

Top ↑

Related terms found for this post

wp-parser-related-wordsattach, attachment, attachments, get, imag, image, images, media-php, post-typ, post-type, wp-get, wp-includes
wp-parser-packageMedia, WordPress

Top ↑

Terms Used Terms Used

Terms used in the related posts query

  • attach
  • attachment
  • attachments
  • get
  • imag
  • image
  • images
  • Media
  • media-php
  • post-typ
  • post-type
  • wp-get
  • wp-includes
  • wp-includes/media.php
  • media

Top ↑

Description Description

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.

Top ↑

Parameters Parameters


(int) (Required) Image attachment ID.


(string|array) (Optional) Image size. Accepts any valid image size, or an array of width and height values in pixels (in that order).

Default value: 'thumbnail'


(bool) (Optional) Whether the image should be treated as an icon.

Default value: false


(string|array) (Optional) Attributes for the image markup.

Default value: ''

Top ↑

Return Return

(string) HTML img element or empty string on failure.

Top ↑

Source Source

File: wp-includes/media.php


Top ↑

Changelog Changelog

Version Description
2.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.