Created
May 31, 2016 15:37
-
-
Save aurooba/fa72f9fcd4b29a623cc171e822e38dda to your computer and use it in GitHub Desktop.
Post Thumbnail (Featured Image) Captions in WordPress
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
| /** | |
| * Check if Post Thumbnail (Featured Image) has a caption, return true if it does | |
| */ | |
| function has_post_thumbnail_caption() { | |
| global $post; | |
| $thumbnail_id = get_post_thumbnail_id($post->ID); | |
| $thumbnail_image = get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment')); | |
| $thumbnail_excerpt = $thumbnail_image[0]->post_excerpt; | |
| if ($thumbnail_excerpt) { | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } |
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
| /** | |
| * Display Post Thumbnail (Featured Image) Caption | |
| */ | |
| function the_post_thumbnail_caption() { | |
| global $post; | |
| $thumbnail_id = get_post_thumbnail_id($post->ID); | |
| $thumbnail_image = get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment')); | |
| if ($thumbnail_image && isset($thumbnail_image[0])) { | |
| echo '<span>'.$thumbnail_image[0]->post_excerpt.'</span>'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment