Skip to content

Instantly share code, notes, and snippets.

@neilgee
Last active May 13, 2016 10:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neilgee/2c9b34fb81e26a1a6fa7 to your computer and use it in GitHub Desktop.
Save neilgee/2c9b34fb81e26a1a6fa7 to your computer and use it in GitHub Desktop.
Custom Headers
<?php //<~ don't add me
<?php if ( get_header_image() ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
</a>
<?php endif; // End header image check. ?>
<?php
//* Add support for custom header
add_theme_support( 'custom-header', array(
'header_image' => '',
'header-selector' => '.site-title a',
'header-text' => false,
'height' => 90,
'width' => 260
'header-text' => false,
) );
<?php //<~ Don't add me
// Add in custom header support.
// Parameters - https://codex.wordpress.org/Custom_Headers
// Need to add in flex-height and flex-width to be able to skip cropping in the Customizer.
add_theme_support( 'custom-header', array(
'width' => 400,
'height' => 150,
'flex-height' => true,
'flex-width' => true,
'header-text' => false,
) );
//// Remove Genesis header style so we can use the customiser and header function genesischild_swap_header to add our header logo.
remove_action( 'wp_head', 'genesis_custom_header_style' );
/**
* Add an image tag inline in the site title element for the main logo
*
* The header logo is then added via the Customiser
*
* @param string $title All the mark up title.
* @param string $inside Mark up inside the title.
* @param string $wrap Mark up on the title.
* @author @_AlphaBlossom
* @author @_neilgee
*/
function genesischild_swap_header( $title, $inside, $wrap ) {
// Set what goes inside the wrapping tags.
if ( get_header_image() ) :
$logo = '<img src="' . get_header_image() . '" width="' . esc_attr( get_custom_header()->width ) . '" height="' . esc_attr( get_custom_header()->height ) . '" alt="' . esc_attr( get_bloginfo( 'name' ) ) . '">';
else :
$logo = get_bloginfo( 'name' );
endif;
$inside = sprintf( '<a href="%s" title="%s">%s</a>', trailingslashit( home_url() ), esc_attr( get_bloginfo( 'name' ) ), $logo );
// Determine which wrapping tags to use - changed is_home to is_front_page to fix Genesis bug.
$wrap = is_front_page() && 'title' === genesis_get_seo_option( 'home_h1_on' ) ? 'h1' : 'p';
// A little fallback, in case an SEO plugin is active - changed is_home to is_front_page to fix Genesis bug.
$wrap = is_front_page() && ! genesis_get_seo_option( 'home_h1_on' ) ? 'h1' : $wrap;
// And finally, $wrap in h1 if HTML5 & semantic headings enabled.
$wrap = genesis_html5() && genesis_get_seo_option( 'semantic_headings' ) ? 'h1' : $wrap;
$title = sprintf( '<%1$s %2$s>%3$s</%1$s>', $wrap, genesis_attr( 'site-title' ), $inside );
return $title;
}
add_filter( 'genesis_seo_title','genesischild_swap_header', 10, 3 );
/**
* Add class for screen readers to site description.
* This will keep the site description mark up but will not have any visual presence on the page
* This runs if their is a header image set in the Customiser.
*
* @param string $attributes Add screen reader class.
* @author @_AlphaBlossom
* @author @_neilgee
*/
function genesischild_add_site_description_class( $attributes ) {
if ( get_header_image() ) :
$attributes['class'] .= ' screen-reader-text';
return $attributes;
endif;
return $attributes;
}
add_filter( 'genesis_attr_site-description', 'genesischild_add_site_description_class' );
<?php //<~ don't add me
//add in custom header support
//parameters - https://codex.wordpress.org/Custom_Headers
add_theme_support( 'custom-header', array(
'width' => 400,
'height' => 150,
'header-text' => false,
'flex-height' => true,
'flex-width' => true,
) );
remove_action( 'wp_head', 'genesis_custom_header_style'); //remove custom genesis custom header style
add_action('genesis_site_title','wpb_image_header', 5);//add in custom header markup via genesis_site_title hook
function wpb_image_header() {
?>
<?php if ( get_header_image() ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
</a>
<?php endif; // End header image check. ?>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment