The wp_get_nav_menu_items()
function returns an indexed array of WP_Post objects.
Here is an example:
$menu_name="custom_menu_slug";
$menu_locations = get_nav_menu_locations()
$menu = wp_get_nav_menu_object( $menu_locations[ $menu_name ] );
$menu_items = wp_get_nav_menu_items( $menu->term_id );
$menu_list="<ul id="menu-" . $menu_name . '">';
foreach ( (array) $menu_items as $key => $menu_item ) {
$menu_list .= '<li><a href="' . $menu_item->url . '">' . $menu_item->title . '</a></li>';
}
$menu_list .= '</ul>';
Source: http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items
Related Posts:
- How to Hard Code Custom menu items
- Removing container from wp_nav_menu not working
- Check if page is in a certain menu
- How to stop mobile theme inheriting desktop navigation menu?
- Increase search results for Admin -> Appearance -> Menus -> Search (default is 10)
- Is it possible to add classes to list items in wp_nav_menu()?
- How do I add the data-toggle=”modal” data-target=”#myModal” attribures to a WP Nav bar?
- How do I fix this error: Warning: invalid argument supplied for foreach()?
- Exclude one item from wp_list_pages( $args );
- if role is logged in then do something
- Nav menu items disappearing (but not immediately)
- Page not appearing in navigation bar
- How to add text before WordPress menu item href
- Nav walker, bootstrap: Display 3rd level items under 2nd level
- Remove nav_menus from customizer using a theme
- Extend WordPress REST API to show slugs for menu items
- WordPress Custom Menu Widget Style
- Output menu navigation in php file
- Custom Post type menu highlighted in the archive/post
- display only the wp_nav_menu, which has the current-menu-item
- Unclickable Menu Item Label in Custom Menu with Clickable Children
- Add tabindex to navmenu
- wp_list_pages sort order is different for different languages [closed]
- Remove Metabox from Menus screen
- Sort wp_nav_menu() by menu order
- How to have custom menu Item CSS Classes for wp_page_menu() or wp_list_pages()
- I’m having a lot of trouble since upgrade to 3.0.1 with get_page_children() function
- How can I add a link to a WPForms “contact us” form to the main menu?
- How to fix “Supplied nav_menu_item value missing property” after update to WordPress 5.0
- How to add programmatically all pages and children to backend menu
- WordPress 3.5 dropdown menu
- Separator for custom nav menu
- add_submenu_page function to show videos table
- WP Menu Walker – How to know total depth from inside the start_lvl() method
- How do I add recent posts to the menu?
- Conditional secondary menus
- Create a MegaMenu using a walker and the start_lvl function
- Nav and logo loading each time causing menu to move JointsWP – Foundation 6
- WordPress Plugin menu position overwrite other item
- Creating a menu containing categories and authors
- Change submenu markup
- Get page slug/id from position in menu
- Two different “Home” items in custom menus dashboard section
- list category posts under its item in menu
- How to re-arrange the MENU of “Allure Real Estate Theme for Placester” wordpress theme?
- Use another menu when logged in
- Using _s theme, menu changes do not affect header menu
- Change class-name on “current_ancestor” in wp_nav_menu
- styling wp_nav_menu – horizontal, sub-menu drop downs
- Show children (sub-navigation) of active menu item only
- Highlighting top level link when viewing one of it’s sub-pages, which are not linked in the menu
- Make menu items open in new tab/page
- Adding top level items in the admin menu that link to a post
- How do I hide “Pages”, “Media”, “Comments”….for editor role?
- how to change the color of menu text wordpress?
- Need a menu on left sidebar of the page with below requirements [closed]
- add login menu with submenu
- Walker Class: Output Parent Description and Featured Image right after sub-menu?
- How to make top level menu think it has a current item
- Drop Down menu expanded by default (on front page) [closed]
- Dynamically get the meta key value of a menu item based on it’s post ID
- Does this function wp_get_nav_menu_object check if a nav menu exists or is supported?
- Wrap wp_nav_menu output around option tags for select menu
- How to get current pages menu text?
- Search form as list item in menu?
- Catagorized hierarchy menu for PAGES!
- Most allowed Taxonomies in Appearance->Menus
- wp_nav_menu removing containing UL with ‘items_wrap’ => ‘%3$s’ not working
- Option to create menu is missing
- New menu is not showing in api response
- Newly created header is not visible on website
- Event listener callback returns undefined element
- Add class to sub-menu from unrelated element
- Copied site has wrong menu URL behaviour
- Add CSS Class to WordPress Menu Item Dependent on the Page the User is Visiting
- Menu walker: how to tell if a sub menu contains submenus?
- Sub Menus will not work
- How do i make a custom top level dashboard menu item available for all users?
- Walker or wp_get_nav_menu_items VS jQuery
- I can’t correctly display menu
- Is it possible to seperate wordpress menu by different div?
- Primery Menu Configuration problem
- Disappearing items in menu
- Menu not saving in dashboard
- Menus not showing in the admin menu, after save
- Where these arguments are defined?
- How do i keep my current page menu highlighted on pagination?
- Add Protocol to Custom Menus
- Menu support for touch devices
- WordPress Flyout Menus
- Pick out specific menu item from code
- Show All Children of WordPress Menu
- menu doesn’t show in different languages
- How to make an anchored page in a navigation menu tab
- Change menu item order
- Menu System: Custom Links
- highlight parent page on menu when child page is on sidebar (and not on menu)
- nav tag wrapping around dropdown
- Resolve the debugs
- Formatting WordPress Menus (without bullets, inline with text)