Skip to content

Instantly share code, notes, and snippets.

@jamiemitchell
Forked from thatwebguy/gist:8335405
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save jamiemitchell/647da62bbe0f5a1a324d to your computer and use it in GitHub Desktop.

Select an option

Save jamiemitchell/647da62bbe0f5a1a324d to your computer and use it in GitHub Desktop.
<?php
// Adding option to use featured image (if it exists)
// in place of background image
remove_action( 'genesis_after_header', 'beautiful_site_header_banner'); // removes existing banner image
add_image_size( 'featured-banner', 2000, 200, TRUE ); // creates a featured image size for the banner
function amcs_featured_img() {
if ( has_post_thumbnail() ) { // checks post has thumbnail
// gets URL for that image
$background = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'featured-banner' );
if (is_array($background)) {
// thanks to @magicroundabout for the fix
// echo the output
echo '<div class="featured-header-banner" style="background: url(' ;
echo $background[0];
echo ') no-repeat scroll center center #FFFFFF"></div>';
}}
else { // if no featured image, adds class to use existing banner
echo '<div class="site-header-banner"></div>';
}}
add_action( 'genesis_after_header', 'amcs_featured_img' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment