Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created April 22, 2016 14:38
Show Gist options
  • Save hellofromtonya/c12c98634b76b7700b835bcfbeea6745 to your computer and use it in GitHub Desktop.
Save hellofromtonya/c12c98634b76b7700b835bcfbeea6745 to your computer and use it in GitHub Desktop.
Proposed fix for Genesis header right widgets
function genesis_header_body_classes( array $classes ) {
if ( current_theme_supports( 'custom-header' ) ) {
if ( get_theme_support( 'custom-header', 'default-text-color' ) !== get_header_textcolor() || get_theme_support( 'custom-header', 'default-image' ) !== get_header_image() )
$classes[] = 'custom-header';
}
if ( 'image' === genesis_get_option( 'blog_title' ) || ( get_header_image() && ! display_header_text() ) )
$classes[] = 'header-image';
// Instead of this conditional to set the header-full-width use the one below instead
// if ( ! is_active_sidebar( 'header-right' ) && ! has_action( 'genesis_header_right' ) )
// $classes[] = 'header-full-width';
if ( ! genesis_is_header_right_ok_to_render() ) {
$classes[] = 'header-full-width';
}
return $classes;
}
/**
* Checks if the `header-right` sidebar is ready to render, meaning it has either of these states:
* 1. registered and has at least one widget in it
* 2. `genesis_header_right` has an action registered to it.
*
* @since 1.0.0
*
* @return bool
*/
function genesis_is_header_right_ok_to_render() {
global $wp_registered_sidebars;
return ( isset( $wp_registered_sidebars['header-right'] ) && is_active_sidebar( 'header-right' ) ) ||
has_action( 'genesis_header_right' );
}
@hellofromtonya
Copy link
Author

Here is the scenario:

  1. Current theme has header right sidebar in it and widgets are active.
  2. Unregister the header right sidebar, we do not get 'header-full-width' because the widgets are active.

It needs an additional check to see if the sidebar is even registered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment