Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get WP menu in array form

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 352
    Comment on it

    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 
    }
    

    In above code $menu_name is a variable which defines the menu location of WP.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: