I had to create a separate Genesis Header-Right Widget Area for a client that needed to display different elements on posts in a certain category.
Create the Extra Widget Area and Initialize It
//Add in new Header Right area function cgp_extra_widgets() { genesis_register_sidebar( array( 'id' => 'HeaderRight2', 'name' => __( 'headerright2', 'genesischild' ), 'description' => __( 'This is the Header Right2 Position', 'genesischild' ), ) ); } add_action( 'widgets_init', 'cgp_extra_widgets' );
Conditionally Create the New Header for Header Right Widget 2
function cgp_remove_header() { if (is_single('') && in_category('red') ) { remove_action( 'genesis_header', 'genesis_do_header' ); add_action( 'genesis_header', 'cgp_special_header' ); } function cgp_special_header() { //my new header code genesis_markup( array( 'html5' => '<div %s>', 'xhtml' => '<div id="title-area">', 'context' => 'title-area', ) ); do_action( 'genesis_site_title' ); do_action( 'genesis_site_description' ); echo '</div>'; genesis_markup( array( 'html5' => '<aside %s>', 'xhtml' => '<div class="widget-area header-widget-area">', 'context' => 'header-widget-area', ) ); dynamic_sidebar( 'headerright2' ); genesis_markup( array( 'html5' => '</aside>', 'xhtml' => '</div>', ) ); } } add_action('get_header', 'cgp_remove_header');
So the above is one whole function followed by an action. The first part of the function cgp_remove_header looks to conditionally remove the default Genesis header only in single posts that belong to the category red. You can string multiple conditions here or just leave it at one. So the header is removed from those pages and a new one is created cgp_special_header.
The nested function cgp_special_header then re-creates the header with genesis_markup , the new widget area is called into the code dynamic_sidebar( ‘headerright2’ );
Finally the cgp_remove_header is actioned by the get_header function.
Full Gist
References Sridhar Katakam and Ryan Meier