Created
November 9, 2013 13:22
-
-
Save vanbernaert/7385376 to your computer and use it in GitHub Desktop.
wp custom nav. this is also outputting every menu item found in wp, and not only a specific custom menu 'test'. registering or not doesn't make a difference.
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 | |
$menu_name = 'test'; | |
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) { | |
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] ); | |
$menu_items = wp_get_nav_menu_items($menu->term_id); | |
$menu_list = '<a>test</a><nav id="bt-menu" class="bt-menu"><ul id="menu-' . $menu_name . '">'; | |
foreach ( (array) $menu_items as $key => $menu_item ) { | |
$title = $menu_item->title; | |
$url = $menu_item->url; | |
$menu_list .= '<li><a href="' . $url . '">' . $title . '</a></li>'; | |
} | |
$menu_list .= '</ul></nav>'; | |
} else { | |
$menu_list = '<ul><li>Menu "' . $menu_name . '" not defined.</li></ul>'; | |
} | |
$defaults = array( | |
'theme_location' => 'codrops', | |
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', | |
'depth' => 0, | |
); | |
wp_nav_menu( $defaults ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment