Skip to content

Instantly share code, notes, and snippets.

@collinprice
Created July 4, 2013 02:55
Show Gist options
  • Save collinprice/5924576 to your computer and use it in GitHub Desktop.
Save collinprice/5924576 to your computer and use it in GitHub Desktop.
Wordpress Divided Menu
function slice_menu($menu_name) {
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 = '<dl class="sub-nav">';
$menu_counter = count($menu_items);
foreach ( (array) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
$url = $menu_item->url;
$menu_list .= '<dd><a href="' . $url . '">' . $title . '</a></dd>';
$menu_counter-- != 1 ?
$menu_list .= '<dd>|</dd>'
: '';
}
$menu_list .= '</dl>';
} else {
$menu_list = '<dl><dd>Menu "' . $menu_name . '" not defined.</dd></dl>';
}
echo $menu_list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment