Advertisement
srikat

Untitled

Jul 1st, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. add_action( 'genesis_before_entry', 'sk_featured_image' );
  2. /**
  3. * Display featured image (if present) before entry on single Posts
  4. */
  5. function sk_featured_image() {
  6. // if we are not on a single Post having a featured image, abort.
  7. if ( ! ( is_singular( 'post' ) && has_post_thumbnail() ) ) {
  8. return;
  9. }
  10.  
  11. // get the URL of featured image.
  12. $image = genesis_get_image( 'format=url&size=post-image' );
  13.  
  14. // get the alt text of featured image.
  15. $thumb_id = get_post_thumbnail_id( get_the_ID() );
  16. $alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true );
  17.  
  18. // get the caption of featured image.
  19. $caption = get_post( $thumb_id )->post_excerpt;
  20.  
  21. // Construct the caption HTML if caption is present for the featured image..
  22. $caption_html = $caption ? '<figcaption class="wp-caption-text">'. $caption . '</figcaption>' : '';
  23.  
  24. // display the featured image.
  25. printf( '<figure class="single-post-image wp-caption"><img src="%s" />%s</figure>', esc_url( $image ), $caption_html );
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement