Skip to content

Instantly share code, notes, and snippets.

@jabaltorres
Created February 24, 2019 04:07
Show Gist options
  • Save jabaltorres/173b0b8cb32002b238237b63b6f21eb5 to your computer and use it in GitHub Desktop.
Save jabaltorres/173b0b8cb32002b238237b63b6f21eb5 to your computer and use it in GitHub Desktop.
Display WP featured image captions and descriptions
<?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 '';
}
?>
@jabaltorres
Copy link
Author

@jabaltorres
Copy link
Author

<?php the_post_thumbnail_caption(); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment