daily pastebin goal
70%
SHARE
TWEET

header image description

alchymyth Aug 30th, 2012 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*alchymyth // http://www.transformationpowertools.com/wordpress/show-description-for-header-images-in-twenty-eleven
  3. //show a description with the (random) header images in Twenty Eleven*/
  4. //check for the pre-set images and their 'description' as set in functions.php of Twenty Eleven or adjusted in functions.php of a child theme//
  5. if ( function_exists( 'get_custom_header' ) && is_child_theme() ) :
  6. if( get_custom_header()->description ) {
  7. $header_description = get_custom_header()->description;
  8. }
  9. //check for post thumbnail in single post or page with sufficient size to be a header image//
  10. elseif ( is_singular() && has_post_thumbnail( $post->ID ) && ( /* $src, $width, $height */ $header_img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, max($header_image_width,$header_image_height) ) ) ) && $header_img[1] >= $header_image_width ) {
  11. $header_img_details = get_posts(array('p' => get_post_thumbnail_id( $post->ID ), 'post_type' => 'attachment'));
  12. $header_description = $header_img_details[0]->post_content;
  13. //alternative if you want to use the 'caption'//
  14. //$header_description = $header_img_details[0]->post_excerpt;
  15. }
  16. //check for the custom uploaded images and their 'description' as added in the media panel//
  17. elseif( $att_id = get_custom_header()->attachment_id ) {
  18. $header_img_details = get_posts(array('p' => $att_id, 'post_type' => 'attachment'));
  19. $header_description = $header_img_details[0]->post_content;
  20. //alternative if you want to use the 'caption'//
  21. //$header_description = $header_img_details[0]->post_excerpt;
  22. }
  23. if( $header_description ) echo '<span class="header-description">' . $header_description . '</span>';
  24. endif;
  25. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top