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
- I only want to show links to categories that have posts in ‘publish’ state in my menu
- 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
- Customize Widget Navigation
- Additional navigation bar in header
- if role is logged in then do something
- How to change how WordPress renders navigation menu on Block Themes
- Problem with links once in portfolio item
- How do I add 3rd level of dropdowns to wp_nav_menu array?
- WP Menu Rollover Nav Item and Effect DIV Elsewhere
- need help in wordpress navbar setup
- Help with WordPress Custom Nav Walker
- Why is my navigation in my onepage not working?
- url_to_postid method in walker_nav navigation menu causing exceptionally high TTFB
- Navigation item – current date in url
- Add Different Class on Different Ul in twenty-twentyone theme
- Get Each Menu Nav Label of Menus in HTML tag
- Hide a menu (navigation bar) on all posts
- insert an HTML element if there is a submenu only
- Nav Menu: Theme Location not working
- Is it all right to put the whole tag into template_part file?
- How to remove empty line space in navigation menu?
- How to change the navigation menu
- Is it possible to get_the_post_thumbnail (Featured Image) inside a sprintf function?
- wp_nav_menu container style args
- Add/remove image from navigation bar
- Can I now add a class in the anchor of my menu item with WordPress 5.4?
- Misleading behaviour on Menu & Theme location
- Bootstrap Theme Migrated to WordPress
- WordPress + Bootstrap: Replace primary navigation menu on mobile?
- WordPress nav_menu items from another menu appearing
- How can I click the parent menu then redirect to a special URL?
- How do I display menu in header without loosing styles?
- What is inside in $item in start_el function in Walker_Nav_Menu class
- Multi-Level Nav Bar
- Adding additional html to the end of the root level in a custom nav walker
- How can I order these pages in this navigation bar on this old wordpress theme?
- Navbar is hidden behind carousel when using wp-boostrap-navwalker
- WordPress Menu Navigation links not working
- Change markup for just 2nd list element in custom Walker menu
- Bootstrap Nav Walker Sub Menu Image
- Creating navigation out of specific IDs and their children?
- 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 ?
- Additional CSS for the nav menu
- Add href to tag in nav menu for mobile
- Add active class to wp_nav_menu
- Output existing wp_nav_menu with a custom walker
- Navigation bar is on live site but nothing under menu so can’t add in a page
- Disable Top Nav Bar on Mobile
- how to split vertical menu into two columns using walker nav menu
- Sub-Items Not Visible in Navigation
- Why does WordPress convert absolute URLs to relative URLs for menu items?
- Menu location switcher – example code fails
- How can I create this menu with wp_nav_menu()?
- Building a menu from a large number of pages?
- Unable to remove page from primary menu
- how to configure this type of menu
- Add Featured Image and Title to wp_nav_menu items
- Add data-track to links in menu
- How to select particular menu position in wordpress?
- Header lists posts instead of showing primary nav menu
- Add Class to Custom Menu Widget ul
- Show navigation header menu by post and categery
- Links in new menu don’t work
- Conditional Nav Menu Inside Nav Menu Across Multisite Sites
- Is it possible to seperate wordpress menu by different div?
- How to add odd and even classes to all nav links through walker?
- Output sort number in wp menu list item?
- Add newsletter signup element to navigation bar
- How to Use Default Auto-Generated Menu?
- wp-nav menu with custom walker , how to remove a tag if it has any submenu
- Programmatically add a Navigation menu and menu items
- Menu Details Output in Javascript [closed]
- Site-wide tabs at WordPress website?
- Custom location for menu
- Creating custom Menu for custom theme
- Check in walker if current page is descendant
- How to add class and span to
- Avoid changing menu query with suppress_filters => false
- wp_nav_menu not selecting teh correct menu
- Show Child of Parent Page including all other parents
- Can’t add optional class to menu item when using Walker_Nav_Menu
- Active page link not getting class assigned
- Removing menu item doesn’t get removed on edit post
- Add dynamic content block to nav section generated by custom walker
- Highlighting Main Navigation Menu With Two or More Class Matches
- Next/previous a-like single navigation
- nav_menu: how to force a subpage switching on the parent menu
- wp_dropdown_nav function to list menu items