Created
June 28, 2019 15:50
-
-
Save moxdev/c41e53f5fc4f9830a8ca4bae315ab27d to your computer and use it in GitHub Desktop.
Get Metadata of Post Thumbnail #wp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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