0

I am creating options for my theme, to customize and style menu items trough theme customizer.

Each menu item will have its own options to change icon next to it and color. As I don't know how much menu items there will be, I have to create options and settings dynamically.

I have a code that is somewhat working:

  $my_menu_object = wp_get_nav_menu_object("Main menu");
  $my_menu_items_count = $my_menu_object->count;

    for($x = 0; $x < $my_menu_items_count; $x++){
        $wp_customize->add_setting( 'my_menu_icon_' . $x, array( 
            'default' => ' '
         ) );
        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'my_menu_icon_' . $x, array(
            'label' => 'Menu icon' . $x,
            'section' => 'usce_menu_icons',
            'settings' => 'my_menu_icon_' . $x,
        ) ) );
    }

But the thing is, this also counts sub-menu items, meaning if any of the menu items have children, it will count. But, I need to count only top-level menu items without submenu items.

Let me know if you have any idea how to work around this.

Your Answer

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

Browse other questions tagged or ask your own question.