Advertisement
Guest User

My header.php code

a guest
Jan 10th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. <?php
  2.     // Check to see if the header image has been removed
  3.     $header_image = get_header_image();
  4.     if ( ! empty( $header_image ) ) :
  5.         if ( function_exists( 'get_custom_header' ) ) {
  6.             // We need to figure out what the minimum width should be for our featured image.
  7.             // This result would be the suggested width if the theme were to implement flexible widths.
  8.             $header_image_width = get_theme_support( 'custom-header', 'width' );
  9.         }
  10.         ?>
  11. <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
  12.     <?php
  13.         // The header image
  14.         // Check if this is a post or page, if it has a thumbnail, and if it's a big one
  15.         if ( is_singular() && has_post_thumbnail( $post->ID ) &&
  16.                 ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ) ) &&
  17.                 $image[1] >= $header_image_width ) :
  18.             // Houston, we have a new header image!
  19.             echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
  20.         else :
  21.             if ( function_exists( 'get_custom_header' ) ) {
  22.                 $header_image_width  = get_custom_header()->width;
  23.                 $header_image_height = get_custom_header()->height;
  24.             }
  25.             ?>
  26.         <img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
  27.     <?php endif; // end check for featured image or standard header ?>
  28. </a>
  29. <?php endif; // end check for removed header image ?>
  30.  
  31. Output of this code:
  32.  
  33. <img width="624" height="187" src="http://matulaitismission.org/wp-content/uploads/2013/01/Matulaicio-Misijos-Prakartele-624x187.jpg" class="attachment-post-thumbnail wp-post-image" alt="Matulaicio-Misijos-Prakartele" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement