wp_get_attachment_image_url( int $attachment_id, string|int[] $size = 'thumbnail', bool $icon = false ): string|false
Gets the URL of an image attachment.
Parameters
-
$attachment_id
int Required -
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'
.Default:
'thumbnail'
-
$icon
bool Optional -
Whether the image should be treated as an icon.
Default:
false
Return
string|false Attachment URL or false if no image is available. If $size
does not match any registered image size, the original image URL will be returned.
Source
File: wp-includes/media.php
.
View all references
function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
$image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
return isset( $image[0] ) ? $image[0] : false;
}
Changelog
Version | Description |
---|---|
4.4.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
For whoever, like me, is looking for the standard sizes, here they are:
thumbnail
= Thumbnail (default 150px x 150px max)medium
= Medium resolution (default 300px x 300px max)large
= Large resolution (default 1024px x 1024px max)full
= Full resolution (original size uploaded)Now let display somewhere:
Add this snippet to the head section in header.php to preload the attachment image on every page/post.
Top ↑
Feedback
Recommend performing a check that the current page/post has a post thumbnail before adding the preload directive. — By crstauf —