Community Forums › Forums › Archived Forums › Design Tips and Tricks › Replace Header
Tagged: replace header code
- This topic has 4 replies, 2 voices, and was last updated 8 years, 8 months ago by Christoph.
-
AuthorPosts
-
July 23, 2015 at 7:41 am #160202Doak HeggenessMember
Why does the following code not work to replace the 'header'? I want to replace the 'header-right' sidebar for a specific page. I got the code from 'lib/structure/header.php' of Genesis.
genesis_register_sidebar( array( 'id' => 'header-right-2', 'name' => __( 'Header Right 2', 'agency' ), 'description' => __( 'This is the Header Right 2 Position', 'agency' ), ) ); // Replace Header Right Sidebar add_action( 'genesis_header', 'dh_replace_header_right_sidebar' ); function dh_replace_header_right_sidebar() { if( is_page( 2180 ) ) { remove_action( 'genesis_header', 'genesis_do_header' ); add_action( 'genesis_header', 'genesis_do_new_header' ); } } function genesis_do_new_header() { global $wp_registered_sidebars; 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>'; if ( ( isset( $wp_registered_sidebars['header-right-2'] ) && is_active_sidebar( 'header-right-2' ) ) || has_action( 'genesis_header_right' ) ) { genesis_markup( array( 'html5' => '<aside %s>', 'xhtml' => '<div class="widget-area header-widget-area">', 'context' => 'header-widget-area', ) ); do_action( 'genesis_header_right' ); add_filter( 'wp_nav_menu_args', 'genesis_header_menu_args' ); add_filter( 'wp_nav_menu', 'genesis_header_menu_wrap' ); dynamic_sidebar( 'header-right-2' ); remove_filter( 'wp_nav_menu_args', 'genesis_header_menu_args' ); remove_filter( 'wp_nav_menu', 'genesis_header_menu_wrap' ); genesis_markup( array( 'html5' => '</aside>', 'xhtml' => '</div>', ) ); } }
Doak Heggeness, WordPress Development | Website
July 24, 2015 at 9:49 am #160303ChristophMemberHi Doak,
change the hook of the first add_action to
genesis_before_header
.
add_action( 'genesis_before_header', 'dh_replace_header_right_sidebar' );
You want the action to execute before the hook that you are changing.
Your code worked on a test site after changing the hook.
July 24, 2015 at 4:14 pm #160368Doak HeggenessMemberJuly 24, 2015 at 4:31 pm #160370Doak HeggenessMemberThanks, that makes perfect sense now. I did have a conflict because I had used the 'remove_action' to remove the header-sidebar on the Home page. Now I can get rid if the 'Custom Sidebars' plugin even though it worked fine.
I used this instead....Is this the most efficient way?
add_action( 'genesis_meta', 'dh_remove_home_header_sidebar'); function dh_remove_home_header_sidebar() { if ( is_home() ) { unregister_sidebar( 'header-right' ); } }
Doak Heggeness, WordPress Development | Website
July 24, 2015 at 5:49 pm #160373ChristophMemberHi Doak,
glad you found the culprit.
Your new code looks good.
genesis_meta seems a bit early to me, but as long as it works 🙂
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.