Created
July 21, 2012 20:34
-
-
Save gyrus/3157070 to your computer and use it in GitHub Desktop.
Get WordPress nav menu without markup containers
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 | |
/** | |
* 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