Created
February 24, 2019 04:07
-
-
Save jabaltorres/173b0b8cb32002b238237b63b6f21eb5 to your computer and use it in GitHub Desktop.
Display WP featured image captions and descriptions
This file contains hidden or 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 | |
/* Only display to logged in users */ | |
if ( is_user_logged_in() ) { | |
/* Displaying the image caption and description */ | |
$thumb_img = get_post( get_post_thumbnail_id() ); // Get post by ID | |
echo '<p>The Caption: ' . $thumb_img->post_excerpt . '<br>'; // Display Caption | |
echo 'The Description: ' . $thumb_img->post_content . '</p> '; // Display Description | |
/* Displaying the image alt text */ | |
$thumb_img_meta = get_post_meta( get_post_thumbnail_id() ); // Get post meta by ID | |
echo $thumb_img_meta['_wp_attachment_image_alt']['0']; // Display Alt text | |
} else { | |
echo ''; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<?php the_post_thumbnail_caption(); ?>