Skip to content

Instantly share code, notes, and snippets.

@robneu
Last active January 8, 2016 23:29
Show Gist options
  • Select an option

  • Save robneu/39fed99bf2a0b9048938 to your computer and use it in GitHub Desktop.

Select an option

Save robneu/39fed99bf2a0b9048938 to your computer and use it in GitHub Desktop.
By default, the Genesis header-right widget area uses an <aside> element. While this is fine most of the time, if you're using the header-right section for your primary navigation it is probably less than ideal for it to be wrapped in an <aside>. This will change the <aside> to a standard <div> element.
<?php
add_filter( 'genesis_markup_header-widget-area_output', 'prefix_opening_header_div', 10, 2 );
/**
* Replace the opening header-right <aside> tag with a <div> tag to allow the
* primary nav to be used in the header without being wrapped in an aside tag.
*
* @param $tag string The current tag for the .header-right widget area.
* @param $args array The current args for genesis_attr()
* @return $tag string The modified tag for the .header-right widget area.
*/
function prefix_opening_header_div( $tag, $args ) {
$tag = '<div ' . genesis_attr( $args['context'] ) . '>';
return $tag;
}
add_filter( 'genesis_markup_', 'prefix_header_closing_div', 10, 2 );
/**
* Replace the closing header-right </aside> tag with a </div> tag to allow the
* primary nav to be used in the header without being wrapped in an aside tag.
*
* @param $tag string The current tag for the .header-right widget area.
* @param $args array The current args for genesis_attr()
* @return $tag string The modified tag for the .header-right widget area.
*/
function prefix_header_closing_div( $tag, $args ) {
if ( did_action( 'genesis_header' ) && ! did_action( 'genesis_after_header' ) ) {
$tag = str_replace( '</aside>', '</div>', $args['html5'] );
}
if ( $args['echo'] ) {
echo $tag;
}
return $tag;
}
@bryanwillis

Copy link
Copy Markdown

Great snippet. This is probably the only example on the entire web of how / when to use the genesis_markup filter. I've been wondering how to use that.

I think for the example with the header right area you could also do this since it's a widget area (correct me if I'm wrong):

function wordpress_widgets_booststrapped_widget_params( $params ) { 
if ( ! is_admin() ) {
    if(isset($params[0]['id']) && $params[0]['id'] == 'header-right'){
      $params[0]['before_widget'] = '';
            $params[0]['after_widget'] = '';      }
        return $params;
  }
}
add_filter( 'dynamic_sidebar_params', 'wordpress_widgets_booststrapped_widget_params', 99 ); 

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