Created
June 25, 2014 18:07
-
-
Save robincornett/654ba3b87db819a034c9 to your computer and use it in GitHub Desktop.
Conditionally replace primary navigation menu for front page. (question here: http://www.studiopress.com/forums/topic/genesis-menus/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add this to your functions file, but do not include the lines above this! | |
add_action( 'template_redirect', 'remove_nav_exclude_blog_page' ); | |
/** | |
* @author Brad Dalton - WP Sites | |
* @learn more http://wpsites.net/web-design/conditionally-remove-your-primary-secondary-nav-menu/ | |
*/ | |
function remove_nav_exclude_blog_page() { | |
if ( is_front_page() ) { | |
remove_action( 'genesis_before_header', 'genesis_do_nav' ); | |
} | |
} | |
add_action( 'genesis_before_header', 'custom_front_page_menu' ); | |
function custom_front_page_menu() { | |
if ( is_front_page() ) { | |
$class = 'menu genesis-nav-menu menu-primary'; | |
if ( genesis_superfish_enabled() ) | |
$class .= ' js-superfish'; | |
$args = array( | |
'theme_location' => 'primary', | |
'container' => '', | |
'menu' => 'front-page-navigation', // !important! you need to give the name/slug of your menu | |
'menu_class' => $class, | |
'echo' => 0, | |
); | |
$nav = wp_nav_menu( $args ); | |
//* Do nothing if there is nothing to show | |
if ( ! $nav ) | |
return; | |
$nav_markup_open = genesis_markup( array( | |
'html5' => '<nav %s>', | |
'xhtml' => '<div id="nav">', | |
'context' => 'nav-primary', | |
'echo' => false, | |
) ); | |
$nav_markup_open .= genesis_structural_wrap( 'menu-primary', 'open', 0 ); | |
$nav_markup_close = genesis_structural_wrap( 'menu-primary', 'close', 0 ); | |
$nav_markup_close .= genesis_html5() ? '</nav>' : '</div>'; | |
$nav_output = $nav_markup_open . $nav . $nav_markup_close; | |
echo apply_filters( 'genesis_do_nav', $nav_output, $nav, $args ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment