Skip to content

Instantly share code, notes, and snippets.

@moxdev
Created June 28, 2019 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moxdev/c41e53f5fc4f9830a8ca4bae315ab27d to your computer and use it in GitHub Desktop.
Save moxdev/c41e53f5fc4f9830a8ca4bae315ab27d to your computer and use it in GitHub Desktop.
Get Metadata of Post Thumbnail #wp
<?php
/**
* Get Metadata of Post Thumbnail
* - An attachment/image ID is all that's needed to retrieve its alt and title attributes.
*
*/
$img_id = get_post_thumbnail_id();
$img_alt = get_post_meta( $img_id, '_wp_attachment_image_alt', true );
$img_title = get_the_title( $img_id );
$img_caption = get_the_post_thumbnail_caption();
// Debugging.
// Gets the metadata array.
$meta = wp_get_attachment_metadata( $img_id );
// Prints readable array to screen.
?>
<pre><?php print_r( $meta ); ?></pre>
<?php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment