Advertisement
srikat

Untitled

Aug 23rd, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. add_action ( 'genesis_after_header', 'sk_featured_image', 9 );
  2. /**
  3.  * Display Featured image after header
  4.  * only on the first page when the Page or Post is divided into multiple using <!--nextpage-->
  5.  *
  6.  * Scope: static Pages and single Posts.
  7.  *
  8.  * @author Sridhar Katakam and Gary Jones
  9.  * @link   http://sridharkatakam.com/, http://gamajo.com/
  10.  */
  11. function sk_featured_image() {
  12.  
  13.     if ( has_post_thumbnail() && ( is_page() || is_single() ) && 0 === get_query_var( 'page' ) ) {
  14.  
  15.         // Get the URL of featured image
  16.         $image = genesis_get_image( 'format=url' );
  17.  
  18.         // Get the alt text of featured image
  19.         $thumb_id = get_post_thumbnail_id( get_the_ID() );
  20.         $alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true );
  21.  
  22.         // If no alt text is present for featured image, set it to Post/Page title
  23.         if ( '' == $alt ) {
  24.             $alt = the_title_attribute( 'echo=0' );
  25.         }
  26.  
  27.         // Display featured image
  28.         printf(
  29.             '<div class="my-featured-image"><img src="%s" alt="%s" class="aligncenter" /></div>',
  30.             esc_url( $image ),
  31.             $alt
  32.         );
  33.  
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement