WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp get attachment metadata

Description

Retrieve attachment meta field for attachment ID.

Usage

<?php wp_get_attachment_metadata$attachment_id$unfiltered ); ?>

Parameters

$attachment_id
(integer) (required) Attachment ID
Default: None
$unfiltered
(boolean) (optional) If true, filters are not run.
Default: false

Return Values

(array|boolean) 
Attachment meta field. False on failure.

The fields are:

width 
(integer) The width of the attachment
height 
(integer) The height of the attachment
file 
(string) The file path relative to `wp-content/uploads/`
sizes 
(array) Keys are size slugs, each value is an array containing 'file', 'width', 'height', and 'mime-type'
image_meta 
(array)

Examples

   Array
   (
       [width] => 2400
       [height] => 1559
       [file] => 2011/12/press_image.jpg
       [sizes] => Array
           (
               [thumbnail] => Array
                   (
                       [file] => press_image-150x150.jpg
                       [width] => 150
                       [height] => 150
                       [mime-type] => image/jpeg
                   )
               [medium] => Array
                   (
                       [file] => press_image-4-300x194.jpg
                       [width] => 300
                       [height] => 194
                       [mime-type] => image/jpeg
                   )
               [large] => Array
                   (
                       [file] => press_image-1024x665.jpg
                       [width] => 1024
                       [height] => 665
                       [mime-type] => image/jpeg
                   )
               [post-thumbnail] => Array
                   (
                       [file] => press_image-624x405.jpg
                       [width] => 624
                       [height] => 405
                       [mime-type] => image/jpeg
                   )
           )
       [image_meta] => Array
           (
               [aperture] => 5
               [credit] => 
               [camera] => Canon EOS-1Ds Mark III
               [caption] => 
               [created_timestamp] => 1323190643
               [copyright] => 
               [focal_length] => 35
               [iso] => 800
               [shutter_speed] => 0.016666666666667
               [title] => 
           )
   )

Notes

Change Log

Since: 2.1.0

Source File

wp_get_attachment_metadata() is located in wp-includes/post.php

Related

Attachment Functions:

get_children(), get attached media(), the_attachment_link(), get_attachment_link(), wp_get_attachment_link(), wp_get_attachment_image(), wp_get_attachment_image_src(), wp_get_attachment_url(), wp_get_attachment_thumb_file(), wp_get_attachment_thumb_url(), is_attachment(), wp_get_attachment_metadata()

See also index of Function Reference and index of Template Tags.