0

How to get Navigation Label as should be of the menu

What is the code for calling or echoing the navigation label of a menu item?

I'm using this code

      <?php 
    $locations = get_registered_nav_menus();
    $menus = wp_get_nav_menus();
    $menu_locations = get_nav_menu_locations();

    $location_id = 'footer_menu1';

    if (isset($menu_locations[ $location_id ])) 
{ 
  foreach ($menus as $menu) 
  {

    if ($menu->term_id == $menu_locations[ $location_id ]) 
    {
      echo '<h2>'.$menu->name.'</h2>';
      // Get the items for this menu
      $menu_items = wp_get_nav_menu_items($menu);

      foreach ( $menu_items as $item )
      {

        $id = get_post_meta( $item->ID, '_menu_item_object_id', true );
        $page = get_page( $id );
        //$link = get_page_link( $id ); ?>
  <li><a href="<?php echo $item->url; ?>" > <?php echo $page->post_title; ?> </a></li>
  <?php 
      }

      break;
    }
  }
    } 
    ?>

Thanks in advanced!

Can I replace <?php echo $page->post_title; ?> with <?php echo $menu->nav_label; ?>

1

Replace $page->post_title; with $item->title; to get the menu item's label

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.