Skip to content

Instantly share code, notes, and snippets.

@gyrus
Created July 21, 2012 20:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyrus/3157070 to your computer and use it in GitHub Desktop.
Save gyrus/3157070 to your computer and use it in GitHub Desktop.
Get WordPress nav menu without markup containers
<?php
/**
* Get nav menu without markup containers
*
* @uses wp_nav_menu()
* @param string $menu The name given to the menu in Appearance > Menus
* @param integer $depth
* @return string
*/
function pilau_menu_without_containers( $menu, $depth = 1 ) {
$menu_items = wp_nav_menu( array(
'menu' => $menu,
'container' => '',
'echo' => false,
'depth' => $depth
));
// Strip ul wrapper
$menu_items = trim( $menu_items );
$menu_items = preg_replace( '#<ul[^>]*>#i', '', $menu_items, 1 );
$menu_items = substr( $menu_items, 0, -5 );
return $menu_items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment