Coolest Guides on the Planet

coolest guides on the planet

Coolest Guides On The Planet

  • Home
  • macOS
  • WebDev
  • All Posts
  • Contact

Create Another Header-Right Widget Area in Genesis Theme to Display on Certain Posts and Categories

February 23, 2014 Leave a Comment

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

 

Cats: Theming, WordPress

Tags

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls

Donate a Beer to the Coolest Guides

Get Beaver Builder Now!

Copyright © 2023· Neil Gee - All Rights Reserved - Hosted by Runcloud

Copyright © 2023 · gee on Genesis Framework · WordPress · Log in