I am not really sure whether there is some native function for this or not, but you could do it like this:
$menu_object = wp_get_nav_menu_object("Main menu");
$menu_items = wp_get_nav_menu_items($menu_object->term_id);
$menu_items_count = 0;
foreach ( (array) $menu_items as $key => $menu_item ) {
if ($menu_item->menu_item_parent == 0 ) $menu_items_count++;
}
Related Posts:
- Adding first / last CSS classes to menus
- Is having multiple theme customizers for different pages possible?
- how to put the logo in the center of other items in the navigation bar
- renaming an admin menu item with decimal array index number
- How can I hook into and edit the text of a wp_nav_menu tag?
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- Can we have a php “page” without a WordPress “page”?
- Check if Favicon is set in Customizer
- removing tags from wp_list_pages() using PHP
- wp_delete_auto_drafts() deletes links in menus
- Dynamically loaded Theme components based on Customizer Settings values : changes not appearing in Customizer preview – (Workaround found)
- WordPress Customizer not setting default value upon initial install?
- Replacing the NavWalker dropdown element
- How to add specific menu on a specific page or pages
- WordPress menu deletes when trying to add a hook
- Logout and redirect using the WP Menu
- Second Navigation inside header
- Creating new menu item
- Crop image from get_theme_mod Customizer field
- Programmatically create menu with custom link
- Get/Set wp.customize.previewer.previewUrl
- Custom Loop through category menu to include sub categories
- selected menu item
- Difference between ‘type’ => ‘text’ and WP_Customize_Control
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- How to display conditional-content if wp_nav_menu( $args ) retruns something
- Can’t extend some core classes
- Show comments menu in dashboard only if the site has comment
- Trouble creating conditional PHP for nav menu items with children for custom Walker
- create a select input with menus created on a custom options page
- From where the header-text can be changed in WordPress custom header?
- Add data attribute to each li in menu
- Remove metabox from WordPress menu editor page?
- How to add an arrow to menu items has submenus
- wp_nav_menu returns menu list in ascending order. How can I arrange the menu same as dashboard menu
- Return a numerical function value in Customizer controls
- Unique icons next to each WordPress menu item
- Customizer: Category Select Sanitize
- Secondary navigation menu on one page
- Remove class in nav_menu_link_attibutes filter
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- Skt full width basic slideshow problem
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- Custom Menus: dynamic highlighting problem with custom home link
- Add item to top of menu using a filter in functions.php
- Adding PHP in the menu
- How to check if a Customizer setting is set?
- How to style one item from main navigation?
- Automatically add images to a menu
- Extending WP_Customize_Media_Control to return filename
- Menu Custom Data Attributes
- How to modify mobile nav menu text in theme
- How can I use custom menus with a Bootstrap WordPress theme?
- Nav menu from plugin to theme
- Adding Additional Variables on Menus Page
- Use SCSSPHP to compile Theme Customizer Values into .SCSS files ready to compile to CSS
- Custom navigation menu with awsAccordion
- Why in this WordPress theme I can’t see the Main Menu?
- wp nav menu: show submenu below li item
- Dynamic Menu drops pages?
- Class for Selected Menu using wp_nav_menu
- Styling an “active” link outside of WordPress default menu
- How to create Loop code for Menu using WordPress?
- Grabing default from cuztomizer php file instead of other php script
- Illegal string offset in PHP function in via Theme Customizer
- Featured image in menu wordpres
- How to set Nav as a default menu in wordpress
- How can I edit a php custom page template to work in other themes?
- Change CSS Variable value in Theme Customizer Live Preview
- Get Child of Child Pages in custom Menu
- PHP warning with code for nav menu walker [duplicate]
- How to disable sub menu items from being created?
- String replace for Login/Logout concatenation problem in menu
- Bring Font Awesome icons inside menu A tags
- Customizer: How to Sanitize a Decimal Number Range
- Display specific main Sub Nav on Woocommerce product pages
- PHP drop down menu for my get_category child of
- Multiple sections in Theme Customizer overwritten
- Sort on two variables
- Using get_theme_mod with checkbox to display content
- Adding button to wordpress menu
- Editing existing pre-created menus in PHP
- Access preview settings in php
- wp_nav_menu prints children with parent name
- WP Admin Bar – Get current theme name as custom menu title
- Active class not working on custom menu link using add_menu_page
- How to add button to top of theme customizer?
- Custom Links in Walker Class
- Submenu opened problem
- WordPress menu links with images & class selection
- Open WordPress Page from selected option dropdown
- How to store the_post_thumbnail() value in a variable
- Remove Unused Menu Locations
- Custom nav with bootstrap dropdown
- Sidebars panel in customizer
- WordPress Customizer add_control Dropdown of Pages with Multi Select?
- make my custom theme support polylang plugin
- How do I create a single.php file as the default template for single posts in the twentytwentythree theme?
- Can’t assign menu parent id or menu item breaks