over 9 years ago
Hello readers, today we will discuss about WP menu.
If you want to get WP menu in array form , you can use below code and will get your menu in array.
- <?php
- /** Get the nav menu based on $menu_name (same as 'theme_location' or 'menu' arg to wp_nav_menu) **/
- $menu_name = 'primary'; // HERE MENU LOCATION
- 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);
- echo "<pre>"; print_r($menu_items); echo "</pre>"; die; //PRINT IN ARRAY
- }
<?php /** Get the nav menu based on $menu_name (same as 'theme_location' or 'menu' arg to wp_nav_menu) **/ $menu_name = 'primary'; // HERE MENU LOCATION 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); echo "<pre>"; print_r($menu_items); echo "</pre>"; die; //PRINT IN ARRAY }
In above code $menu_name is a variable which defines the menu location of WP.
0 Comment(s)