Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*alchymyth // http://www.transformationpowertools.com/wordpress/show-description-for-header-images-in-twenty-eleven
- //show a description with the (random) header images in Twenty Eleven*/
- //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//
- if ( function_exists( 'get_custom_header' ) && is_child_theme() ) :
- if( get_custom_header()->description ) {
- $header_description = get_custom_header()->description;
- }
- //check for post thumbnail in single post or page with sufficient size to be a header image//
- 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 ) {
- $header_img_details = get_posts(array('p' => get_post_thumbnail_id( $post->ID ), 'post_type' => 'attachment'));
- $header_description = $header_img_details[0]->post_content;
- //alternative if you want to use the 'caption'//
- //$header_description = $header_img_details[0]->post_excerpt;
- }
- //check for the custom uploaded images and their 'description' as added in the media panel//
- elseif( $att_id = get_custom_header()->attachment_id ) {
- $header_img_details = get_posts(array('p' => $att_id, 'post_type' => 'attachment'));
- $header_description = $header_img_details[0]->post_content;
- //alternative if you want to use the 'caption'//
- //$header_description = $header_img_details[0]->post_excerpt;
- }
- if( $header_description ) echo '<span class="header-description">' . $header_description . '</span>';
- endif;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement