wp_get_attachment_image_sizes

Retrieves the value for an image attachment's 'sizes' attribute.

Description

(string|bool) wp_get_attachment_image_sizes( (int) $attachment_id, (string) $size = 'medium', (null) $image_meta = null ); 

Returns (string|bool)

A valid source size value for use in a 'sizes' attribute or false.

Parameters (3)

0. $attachment_id (int)
Image attachment ID.
1. $size — Optional. (string) => 'medium'
Image size. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default medium..
2. $image_meta — Optional. (null) => null
The image meta data as returned by wp_get_attachment_metadata().. Default null.

Usage

  1. if ( !function_exists( 'wp_get_attachment_image_sizes' ) ) { 
  2. require_once ABSPATH . WPINC . '/media.php'; 
  3.  
  4. // Image attachment ID. 
  5. $attachment_id = -1; 
  6.  
  7. // Optional. Image size. Accepts any valid image size, or an array of width 
  8. // and height values in pixels (in that order). Default 'medium'. 
  9. $size = 'medium'; 
  10.  
  11. // Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. 
  12. // Default null. 
  13. $image_meta = null; 
  14.  
  15. // NOTICE! Understand what this does before running. 
  16. $result = wp_get_attachment_image_sizes($attachment_id, $size, $image_meta); 
  17.  

Defined (1)

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

/wp-includes/media.php  
  1. function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) { 
  2. if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) { 
  3. return false; 
  4.  
  5. if ( ! is_array( $image_meta ) ) { 
  6. $image_meta = wp_get_attachment_metadata( $attachment_id ); 
  7.  
  8. $image_src = $image[0]; 
  9. $size_array = array( 
  10. absint( $image[1] ),  
  11. absint( $image[2] ) 
  12. ); 
  13.  
  14. return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id );