Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created June 30, 2014 21:56
Show Gist options
  • Save hellofromtonya/2fb800a0f66f931cd4f8 to your computer and use it in GitHub Desktop.
Save hellofromtonya/2fb800a0f66f931cd4f8 to your computer and use it in GitHub Desktop.
Full width Genesis Custom Header
//* Add support for custom header
add_theme_support( 'custom-header', array(
'width' => 1000, // width of the image
'height' => 70, // height of the image
'header-selector' => '.site-header', // sets it to the <header> element
'wp-head-callback' => 'lunarwp_modify_custom_header', // callback so we can modify the css added to the <head>
'header-text' => false,
) );
/**
* Modify the custom header. We are using the standard Genesis code here from
* function function genesis_custom_header_style() in header.php; however, we
* modified the actual css output to allow us to "contain" the image for mobile
* devices.
*
* @since 1.0.0
*
* @return void
*/
function lunarwp_modify_custom_header()
{
$output = '';
$header_image = get_header_image();
$text_color = get_header_textcolor();
//* If no options set, don't waste the output. Do nothing.
if ( empty( $header_image ) && ! display_header_text() && $text_color === get_theme_support( 'custom-header', 'default-text-color' ) )
return;
$header_selector = get_theme_support( 'custom-header', 'header-selector' );
$title_selector = genesis_html5() ? '.custom-header .site-title' : '.custom-header #title';
$desc_selector = genesis_html5() ? '.custom-header .site-description' : '.custom-header #description';
//* Header selector fallback
if ( ! $header_selector )
$header_selector = genesis_html5() ? '.custom-header .site-header' : '.custom-header #header';
//* Header image CSS, if exists
if ( $header_image )
$output .= sprintf( '%s { background-image: url(%s) !important; background-repeat: no-repeat; background-size: contain; }', $header_selector, esc_url( $header_image ) );
//* Header text color CSS, if showing text
if ( display_header_text() && $text_color !== get_theme_support( 'custom-header', 'default-text-color' ) )
$output .= sprintf( '%2$s a, %2$s a:hover, %3$s { color: #%1$s !important; }', esc_html( $text_color ), esc_html( $title_selector ), esc_html( $desc_selector ) );
if ( $output )
printf( '<style type="text/css">%s</style>' . "\n", $output );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment