add_action( 'genesis_before_entry', 'sk_featured_image' );
/**
* Display featured image (if present) before entry on single Posts
*/
function sk_featured_image() {
// if we are not on a single Post having a featured image, abort.
if ( ! ( is_singular( 'post' ) && has_post_thumbnail() ) ) {
return;
}
// get the URL of featured image.
$image = genesis_get_image( 'format=url&size=post-image' );
// get the alt text of featured image.
$thumb_id = get_post_thumbnail_id( get_the_ID() );
$alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true );
// get the caption of featured image.
$caption = get_post( $thumb_id )->post_excerpt;
// Construct the caption HTML if caption is present for the featured image..
$caption_html = $caption ? '<figcaption class="wp-caption-text">'. $caption . '</figcaption>' : '';
// display the featured image.
printf( '<figure class="single-post-image wp-caption"><img src="%s" />%s</figure>', esc_url( $image ), $caption_html );
}
Comments