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:
- wp_get_nav_menu_items() with ACF
- Change CSS Variable value in Theme Customizer Live Preview
- How to switch between two primary menus (programatically0
- How to let mobile navigation menu close when link is clicked?
- Redirect User when they click Menu Option
- Used a code to revoke some dashboard menus for my contributors but for some reason it’s revoked me access to the editor [closed]
- Get Child of Child Pages in custom Menu
- Customizer textarea with script tag won’t work in live preview
- How to give custom roles the capability to edit one Menu instead of every Menu
- Primary navigation menu with timed items from custom post type
- PHP warning with code for nav menu walker [duplicate]
- Add element after navigation element title don’t works like I expect
- 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
- Difference between “Walker_Nav_menu” and “walker”
- Allow user to choose header style
- Remove specific javascript when viewing page in Customizer?
- Add parent menu item in sub-menu in custom nav_walker
- Customizer: How to Sanitize a Decimal Number Range
- How to update option field in database on clicking the publish button in customizer
- How to create a sub-page of sub-page?
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Make customizer panel or section button
- Vertical Menu for one page only
- make an array in wordpress cusmization api?
- 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
- Widget Logic – display on page and all child
- How limit the width of a fixed menu-bar on scroll?
- Use Custiomizer to setup meta theme color tag
- Pulling a variable into the wp_nav_menu function
- Default Image not showing up in Customizer for WP_Customize_Cropped_Image_Control
- Sort on two variables
- Using get_theme_mod with checkbox to display content
- Beyond widget side menu editing, with the php page, custom template
- How to list categories by page id in wordpress
- Adding button to wordpress menu
- customizer live preview layout picker
- Editing existing pre-created menus in PHP
- Two theme locations for two menus, but only one is showing up
- wp_nav_menu doesn’t work in a duplicate server
- How I can add div to menu?
- Access preview settings in php
- wp_nav_menu prints children with parent name
- wp nav menu without label
- Contact form field in wordpress menu
- WP Admin Bar – Get current theme name as custom menu title
- Create Customization Controls from Array
- Add extra markup to WP menus
- How to call a certain object/menubar in a PHP file
- Active class not working on custom menu link using add_menu_page
- Replace content in WordPress Page after GET from php page
- Sidebar current menu item for parent
- Using ‘array’ method in wp_nav_menu causes it to disappear
- Remove all nav menu classes except those which begin with certain letters
- How to add a code for lastpostdate after/inside a specific menu link?
- Add the “.current-menu-item” class to tag?
- How to get the count for each taxonomy term
- WP_Nav Highlight Parent Issue
- How to add button to top of theme customizer?
- WordPress adding in site URL to header links
- How can I clear the theme mod settings?
- Cant get theme to change footer color through theme customizer
- How to change the menu color
- Can’t remove menu items added by plugin
- Custom Links in Walker Class
- Submenu opened problem
- if is_home(), change class of menu-item-225 of wp_nav_menu
- Nav Menu Display
- Adding a unique class to wp_nav_menu
- Change order that the menu is generated with wp_list_pages
- I am extending Walker_Nav_Menu: How can I get the number of children elements of the current item?
- How do I modify the with wp_nav_menu()
- wp_head makes my custom page template not work in Customizer?
- Make a permalink to the most recent blog post
- Echo piece of code from file
- WordPress menu links with images & class selection
- Open WordPress Page from selected option dropdown
- Inserting a shortcode into a genesis menu?
- How to store the_post_thumbnail() value in a variable
- Remove Unused Menu Locations
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- How to add different menu items on different menus?
- Custom nav with bootstrap dropdown
- Nav menù doesn’t display selected pages
- Sidebars panel in customizer
- Show a text in menu
- Capture the Selected Radio Button Value between two files in wordpress theme
- WordPress Customizer – How to save list of checkbox of pages?
- 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?
- Partial refresh in WordPress live preview
- Sections dependent on checkbox the WordPress WP_Customize_Control
- Can’t assign menu parent id or menu item breaks
- Show the terms of the hierarchical taxonomy
- Can’t find elemnts on the DOM using Custom Control in Customizer API
- What is considered good practice for registering menu locations?