wp_get_attachment_image_url

Get the URL of an image attachment.

Description

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

Returns (string|false)

Attachment URL or false if no image is available.

Parameters (3)

0. $attachment_id (int)
Image attachment ID.
1. $size — Optional. (string) => 'thumbnail'
Image size to retrieve. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default thumbnail..
2. $icon — Optional. (bool) => false
Whether the image should be treated as an icon. Default false.

Usage

  1. if ( !function_exists( 'wp_get_attachment_image_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/media.php'; 
  3.  
  4. // Image attachment ID. 
  5. $attachment_id = -1; 
  6.  
  7. // Optional. Image size to retrieve. Accepts any valid image size, or an array 
  8. // of width and height values in pixels (in that order). Default 'thumbnail'. 
  9. $size = 'thumbnail'; 
  10.  
  11. // Optional. Whether the image should be treated as an icon. Default false. 
  12. $icon = false; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = wp_get_attachment_image_url($attachment_id, $size, $icon); 
  16.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/media.php  
  1. function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) { 
  2. $image = wp_get_attachment_image_src( $attachment_id, $size, $icon ); 
  3. return isset( $image['0'] ) ? $image['0'] : false;