Get top items number from wordpress menu

I’ve made a menu in WordPress backend with 3 levels depth.
(four main tabs with two sub level items)

I would like to know how I can get the number of tabs created automatically and add this number to a class on the ul (i.e: .item-4)

Read More

Any ideas? I’m already using a custom walker.

Related posts

Leave a Reply

1 comment

  1. You can use the wp_get_nav_menu_object to retrieve the menu as an object, which you can subsequently establish the length of. Like this:

    $wpse140949_menu = wp_get_nav_menu_object( 'your-menu-name-or-slug' );
    $tabcount = $wpse140949_menu->count;
    

    You can the use this on your call to wp_nav_menu:

    wp_nav_menu ( array (
      'menu_class' => 'item-' . $tabcount,
      ....
      ));