Retrieves attachment metadata for attachment ID.
$attachment_idintrequired
$unfilteredbooloptional
Default:false
width intheight intfile stringwp-content/uploads.sizes array'file', 'width', 'height', and 'mime-type'.image_meta arrayfilesize intfunction wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
$attachment_id = (int) $attachment_id;
if ( ! $attachment_id ) {
$post = get_post();
if ( ! $post ) {
return false;
}
$attachment_id = $post->ID;
}
$data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
if ( ! $data ) {
return false;
}
if ( $unfiltered ) {
return $data;
}
/**
* Filters the attachment meta data.
*
* @since 2.1.0
*
* @param array $data Array of meta data for the given attachment.
* @param int $attachment_id Attachment post ID.
*/
return apply_filters( 'wp_get_attachment_metadata', $data, $attachment_id );
}
Filters the attachment meta data.
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_get_attachment_metadata