Opens in a new tab
A picture of Jeff Brigman
I CODE TODAY FOR
A BETTER TOMORROW

Glossary Term

wp_get_attachment_image()

3 tags 1 category

wp_get_attachment_image() — Gets 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.

Inputs: $attachment_id (int): Image attachment ID. $size (string|int[]): Optional. Image size. Accepts any registered image size name, or an array of width and height values in pixels (in that order). Default ‘thumbnail’. $icon (bool): Optional. Whether the image should be treated as an icon. Default false. $attr (string|array): Optional. Attributes for the image markup. Field $src (string): Image attachment URL. Field $class (string): 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. Field $alt (string): Image description for the alt attribute. Field $srcset (string): The ‘srcset’ attribute value. Field $sizes (string): The ‘sizes’ attribute value. Field $loading (string|false): The ‘loading’ attribute value. Passing a value of false will result in the attribute being omitted for the image. Default determined by wp_get_loading_optimization_attributes(). Field $decoding (string): The ‘decoding’ attribute value. Possible values are ‘async’ (default), ‘sync’, or ‘auto’.

Returns string: HTML img element or empty string on failure.

Term Connections

Explore related terms connected by shared tags, shared categories, and relationship phrases. This map loads only when it comes into view.

Loading term connections…