Filter and Hooks, Programming, WordPress

Get Menu Items Based on Custom Menu

1. Register your custom navigation menu.
We have readily available funtion to register our custom menu, therefore we do not need to call add_theme_support( ‘menus’ ) :


Here, $locations is an associative array of menu location slugs (key) and descriptions (according value). I have registered custom menu ‘primary_menu’ as a key  and ‘Main menu’ is the description for the registered ‘primary_menu’


2. Create and add Menu items the dashboard


3. Get the array of Menu items

Use the custom menu key ‘primary_menu’ in my case to get the  all the menu items associated with it.


4. Function to the get the array of menu items

You can create your own function to get the menu items and its sub-items in an array


Hits: 13