a.hoereth
Member
Posted 1 year ago #
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.
a.hoereth
Member
Posted 1 year ago #
Could someone please help me? Still searching for an solution..
a.hoereth
Member
Posted 1 year ago #
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