You might find yourself in the situation where you need to get the menu items for a particular WordPress menu without grabbing the whole menu markup (for example, the
nav part) itself or maybe you just want get the menu items data to output in your loop elsewhere.
Render the menu items without the nav
In the first scenario, we can render the menu without the container (usually
nav) by using
wp_nav_menu() and setting
container to be blank.
In this example we just need to know the slug for the menu location we’re targeting.
Get the menu items data and render in a custom loop
In the second scenario, we can grab all the menu items data by passing the menu’s slug (rather than the menu location slug) to
wp_get_nav_menu_items() like the following example.
(For this technique you might need to get a WordPress menu from a specific menu location in order to discover the correct menu slug).