Skip to content

Instantly share code, notes, and snippets.

@davechu
Last active February 1, 2016 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davechu/7979941 to your computer and use it in GitHub Desktop.
Save davechu/7979941 to your computer and use it in GitHub Desktop.
This is code that will allow the use of Christian Varga's handy WordPress auto-submenu code.
/** dave's genesis code for making the submenu **/
add_action( 'wp_head', 'dc_add_tricky_menu' );
function dc_add_tricky_menu () {
// make all menus one level, or else dropdowns will be redundant in your submenu.
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
// stick submenu under main menu. Of course you can use other hooks to put menu & submenu elsewhere.
add_action( 'genesis_after_header', 'dc_add_tricky_two' );
}
function my_wp_nav_menu_args( $args = '' ) {
$args['depth'] = 1;
return $args;
}
function dc_add_tricky_two () {
// this code is for retaining styling from the main menu, but giving you a class to re-style the menu if desired.
echo '<nav class="nav-primary submenu" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement"><div class="wrap">';
wp_nav_menu( array(
'theme_location' => 'primary',
'container' => 'false',
'menu_class' => 'genesis-nav-menu',
'sub_menu' => true
) );
echo '</div></nav>';
}
/**** end of dave's submenu code ****/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment