You can wp_nav_menu_objects filter hook and you can compare your menu label with the condition and append your cart count. check below code. code will go active theme functions.php file. tested and works.
function modify_cart_label_in_nav_menu_objects( $items, $args ) {
if($args->theme_location == 'primary'){
foreach ( $items as $key => $item ) {
if ( $item->title == 'test' ) {
$item->title .= '('.WC()->cart->get_cart_contents_count().')';
}
}
}
return $items;
}
add_filter( 'wp_nav_menu_objects', 'modify_cart_label_in_nav_menu_objects', 10, 2 );
Related Posts:
- Why is ‘nav_menu_item_args’ filter’s $item argument empty?
- Third level navigation class
- Dynamically exclude menu items from wp_nav_menu
- remove specific classes from menu items
- Add custom link on the fly to nav menu
- Possible to append class to nav menu added to widget area?
- display cart information within li of cart menu item
- Show thumbnail to category items in wp_nav_menu(), how?
- How to modify menu text in callback function of ‘walker_nav_menu_start_el’ hook
- Displaying a Custom Avatar in WP Bootstrap Navwalker Menus in WordPress
- Add button and title on submenu WordPress
- Is there an easy way to replace a custom menu link with a page or post?
- Add Javascript to WordPress Menu
- Add custom menu item using wp_nav_menu_items filter
- Filter wp_nav_menu()
- Custom search filter causes menu and query_posts problems
- Use navigation path from menu for permalink
- add span class inside wp_nav_menu link anchor tag
- Show only 2nd level of navigation depending on active navigation
- Using filters to change href of nav menu page link
- How to get a different mobile menu than desktop menu in the twentytwelve child theme
- HTML Bootstrap navigation menu to WordPress menu using wp_nav_menu
- WordPress Export Import Site Navigation Menu
- Is it possible to add a filter for the output of nav-menu items in admin?
- Bar separated navigation by extending Walker_Nav_Menu
- Replace menu tag with tag
- Does the ‘nav_menu_css_class’ filter accept 2 or 3 arguments?
- How to style current page menu item when using a walker
- Adding different classes to anchor in navigation menu
- Add Bootstrap dropdown class to a nav menu
- How can I put two menus in the same div?
- BuddyPress – How to add logout in nav menu
- Nav Walker current menu item not displaying
- Navigation (wp_nav_menu) refuses to nest within parent element
- Removing strip_tags not working on nav_menu_description
- Add custom menu item metabox in Navigation Settings
- Auto add pages to primary menu with functions.php
- Get admin menu link
- Hide Menu Unless Logged In
- Highlight another nav item
- How to change theme header to support multiple nav menus?
- How to have the Header show different content on different pages?
- Programmatically add existing pages and subpages to Appearance Menu
- I want to hide the navigation menu on a particular page
- walker – 0 level on submenu formatting
- current-menu-item class not working properly
- wp_nav_menu() doesn’t work
- Insert other menus as submenus of a main menu
- Remove nav menu item by script
- Make a navigation menu in the same post [duplicate]
- Get menus created with menu editor?
- Insert a div before the wp_nav_menu
- How to create a menu with pages and post categories?
- Missunderstanding of WordPress menus
- How to add schema.org SiteNavigationElement and property URL to navbar?
- Theme Location empty
- wp_nav_menu action/filter help
- how to remove description from menu buttons?
- How to buid wordpress menu with auto width sub-menu items in dropdown menu without any items sharing one line [closed]
- Trying to add a custom social icon to a Twenty Twenty-One child theme
- Adding toggle-able element after menu item
- Custom register_taxonomy ins’t showing custom Nav menu
- Conditional menus based on page title
- How to test if a specific page is the front page?
- Style wp_link_pages as a select drop down list
- How to add columns to wordpress menu editor
- how to insert data in li tag of navigation
- Current author archive in navigation menu
- Mobile navigation is shown, but standard navigation does not disappear
- changing the labels inside appearance -> menus for some for the fields
- if role is logged in then do something
- WP Menu Rollover Nav Item and Effect DIV Elsewhere
- How to change the navigation menu
- Add/remove image from navigation bar
- WordPress nav_menu items from another menu appearing
- How can I order these pages in this navigation bar on this old wordpress theme?
- WordPress Menu Navigation links not working
- Modifying Woocommerce menu based on tags and categories
- Where to place a svg chevron down in my custom walker?
- How to apply individual menu item’s “CSS Classes” to , not ?
- Add href to tag in nav menu for mobile
- Output existing wp_nav_menu with a custom walker
- Why does WordPress convert absolute URLs to relative URLs for menu items?
- How can I create this menu with wp_nav_menu()?
- Unable to remove page from primary menu
- Show navigation header menu by post and categery
- How to Use Default Auto-Generated Menu?
- wp-nav menu with custom walker , how to remove a tag if it has any submenu
- Menu Details Output in Javascript [closed]
- Custom location for menu
- Avoid changing menu query with suppress_filters => false
- Determine if a navigation item has children
- wordpress superfish dropdown menu
- Unable to edit Navigation bar
- Site pages show the page title under navigation bar
- Navigation menu, remove item from desktop
- Wrapping my ‘s with
- How to add a class directly on a unordered list element that is a primary navigation
- Get_avatar filter hook not displaying custom avatar image on frontend
- Give custom class names to WP nav sub-menu