1. Use a shortcode to display all menus
You can create a custom shortcode that lists all registered menus, then insert that shortcode into any post.
Here’s a simple way to do it:
Step 1: Add this to your theme’s functions.php
file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | function list_all_menus_shortcode() { $menus = wp_get_nav_menus(); $output = '' ; if (! empty ( $menus )) { foreach ( $menus as $menu ) { $menu_items = wp_get_nav_menu_items( $menu ->term_id); if (! empty ( $menu_items )) { $output .= '<h2>' . esc_html( $menu ->name) . '</h2>' ; $output .= '<ul>' ; foreach ( $menu_items as $item ) { $output .= '<li><a href="' . esc_url( $item ->url) . '">' . esc_html( $item ->title) . '</a></li>' ; } $output .= '</ul>' ; } } } else { $output = '<p>No menus found.</p>' ; } return $output ; } add_shortcode( 'all_menus' , 'list_all_menus_shortcode' ); |
Step 2: Use [all_menus]
shortcode inside your post content.
✅ Now when you insert [all_menus]
into any post or page, it will automatically display all menus with their items.
2. Use a shortcode to print all menu names quoted and separated by a comma
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function print_all_menu_names_shortcode() { $menus = wp_get_nav_menus(); $names = []; if (! empty ( $menus )) { foreach ( $menus as $menu ) { $names [] = '"' . esc_html( $menu ->name) . '"' ; } return implode( ', ' , $names ); } else { return 'No menus found.' ; } } add_shortcode( 'print_menu_names' , 'print_all_menu_names_shortcode' ); |
How to use:
- Add the code to your theme’s
functions.php
or your custom plugin. - Then just put this shortcode wherever you want the menu names to appear:
1 | [print_menu_names] |
✅ This will output something like:
1 | "Main Menu", "Footer Menu", "Sidebar Menu" |
3. Use a shortcode to print all menus in a custom sort
Each WordPress menu has a unique ID ($menu->term_id
) and a name ($menu->name
).
You can identify them either by their ID or by their name.
Then, you manually set the order you want.
Here’s how you can do it:
Update the shortcode function like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | function list_all_menus_shortcode() { $menus = wp_get_nav_menus(); $output = '' ; if (! empty ( $menus )) { // Step 1: Define the hard-coded order you want (by menu ID or menu name) $custom_order = [ 'Main Menu' , // by name 'Footer Menu' , 'Sidebar Menu' , ]; // Step 2: Reorder the menus according to your custom order $ordered_menus = []; foreach ( $custom_order as $name ) { foreach ( $menus as $menu ) { if ( $menu ->name === $name ) { // use $menu->term_id if you want to match by ID $ordered_menus [] = $menu ; break ; } } } foreach ( $ordered_menus as $menu ) { $menu_items = wp_get_nav_menu_items( $menu ->term_id); if (! empty ( $menu_items )) { $output .= '<h2>' . esc_html( $menu ->name) . '</h2>' ; $output .= '<ul>' ; foreach ( $menu_items as $item ) { $output .= '<li><a href="' . esc_url( $item ->url) . '">' . esc_html( $item ->title) . '</a></li>' ; } $output .= '</ul>' ; } } } else { $output = '<p>No menus found.</p>' ; } return $output ; } add_shortcode( 'all_menus' , 'list_all_menus_shortcode' ); |
Important notes:
- Replace
"Main Menu"
,"Footer Menu"
, etc., in$custom_order
with your real menu names. - Alternatively, you can match by
term_id
instead ofname
if you prefer.
👉 To find your menu IDs easily, go to:
WordPress Dashboard → Appearance → Menus, then hover over a menu — you’ll see a URL like:
1 | /wp-admin/nav-menus.php?action=edit&menu=45 |
Here, menu=45
means term_id = 45
.
If you want to match by ID, change the matching line:
1 | if ($menu->term_id == $id) { |
instead of name matching.
This post is also available in: Greek