wp_get_attachment_image_url() WordPress Function

The wp_get_attachment_image_url() function returns the URL for an image attachment. This function can be used with any image attachment, whether it is attached to a post, page, or custom post type. It can also be used with images that are not attached to any content.

wp_get_attachment_image_url( int $attachment_id, string|int[] $size = 'thumbnail', bool $icon = false ) #

Get 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 value: 'thumbnail'

$icon

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

Default value: false


Top ↑

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.


Top ↑

Source

File: wp-includes/media.php

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;
}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More