• Hey there,
    I want to fit the menu differently to the layout depending on how many first level items it got.
    So i just tried to count them, but my script always returns 0.

    $wp_nav_menu_to_count =  wp_nav_menu( array( 'echo' => 'false', 'depth' => '1' ) );
    $wp_nav_menu_counter = substr_count($wp_nav_menu_to_count, 'menu-item');
    echo $wp_nav_menu_counter;

    It worked likewise with wordpress 2.9, but i used a get function there.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Alex

    (@ahoereth)

    Could someone please help me? Still searching for an solution..

    Thread Starter Alex

    (@ahoereth)

    Still searching for a solution.

    Someone?

    $menu_to_count = wp_nav_menu(array(
    	'echo' => false,
    	'theme_location' => 'menu'
    	));
    $menu_items = substr_count($menu_to_count,'class="menu-item ');
    echo $menu_items;

    This should work. Change the theme_location to what your menu is called.

    Greetings,
    Chiel Robben

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘count wp_nav_menu items’ is closed to new replies.