Skip to content

Instantly share code, notes, and snippets.

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 uncatcrea/ecf641281eea35ecfb88 to your computer and use it in GitHub Desktop.
Save uncatcrea/ecf641281eea35ecfb88 to your computer and use it in GitHub Desktop.
//In your theme's php folder for example:
add_filter( 'wpak_post_data', 'wpak_add_thumbnail_caption', 10, 3 );
function wpak_add_thumbnail_caption( $post_data, $post, $component ) {
$thumbnail_id = get_post_thumbnail_id( $post->ID );
if ( $thumbnail_id ) {
$image_post = get_post( $thumbnail_id );
if ( $image_post ) {
if ( !empty( $post_data['thumbnail'] ) ) {
$post_data['thumbnail']['caption'] = $image_post->post_excerpt;
}
}
}
return $post_data;
}
//Then you can use post.thumbnail.caption in single.html and archive.html templates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment