Example: caras.org
| jQuery(function($){ | |
| // Preload header image | |
| var $header = $( '.page-header' ), | |
| headerImage = $header.data( 'image' ); | |
| if ( headerImage ) { | |
| var img = new Image(); | |
| img.src = headerImage; | |
| $ (window ).load( function(){ | |
| $header.css( 'background-image', 'url(' + headerImage + ')' ); | |
| }); | |
| } | |
| }); |
| <?php | |
| /** | |
| * Page Header | |
| * | |
| */ | |
| function ea_page_header() { | |
| $image_id = $title = $content = false; | |
| if( is_singular() && has_post_thumbnail() ) | |
| $image_id = get_post_thumbnail_id(); | |
| if( is_page() ) { | |
| $title = get_the_title(); | |
| remove_action( 'tha_entry_top', 'ea_entry_title' ); | |
| } | |
| if( is_home() ) { | |
| $title = get_the_title( get_option( 'page_for_posts' ) ); | |
| } | |
| if( is_archive() ) { | |
| $title = get_the_archive_title(); | |
| } | |
| if( is_search() ) | |
| $title = 'Search results for: <em>' . get_search_query() . '</em>'; | |
| if( is_home() || is_archive() || is_search() ) | |
| $image_id = get_post_thumbnail_id( get_option( 'page_for_posts' ) ); | |
| if( empty( $image_id ) ) | |
| $image_id = ea_cf( 'ea_header_image', false, array( 'type' => 'theme_option' ) ); | |
| echo '<div class="page-header" data-image="' . wp_get_attachment_image_url( $image_id, 'full' ) . '"><div class="wrap">'; | |
| if( !empty( $title ) ) | |
| echo '<h1>' . $title . '</h1>'; | |
| echo $content; | |
| echo '</div></div>'; | |
| } | |
| add_action( 'tha_header_after', 'ea_page_header' ); |
| .page-header { | |
| background-image: url(../images/loading.png); | |
| background-size: cover; | |
| background-position: center center; | |
| position: relative; | |
| transition: background-image 0.4s ease-in-out; | |
| } |