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
- Programmatically add a Navigation menu and menu items
- Unregister Nav Menu from Child-Theme
- Call custom field into menu item
- Exclude Private, Draft pages from Primary Nav when using custom menu
- wp_nav_menu always falls back to a menu
- wp_get_nav_menu_items how to exclude sub level menu items?
- Add custom attributes to menu items without plugin
- Add Page ID class to nav menu items
- WordPress nav_menu_link_attributes Not Working
- Not able to get current menu ID
- how to automatically generate hierarchical menus from hierarchy of pages?
- WordPress wp_nav_menu with a nav tag
- Add sidebars to navigation menu?
- `start_el` depth argument in custom nav walker always evaluates to zero
- Programmatically set current-menu-item using wp_nav_menu
- How to insert custom code into wp_nav_menu structure?
- Remove li from wp_nav_menu
- Adding post excerpt into navigation menu
- Adding Custom “Current Menu Item” class to navigation?
- How to add #navbar to all page links?
- Check if menu id = $specific_id – then insert specific
- I am facing a problem with the navigation menu of my website
- Prepend to start of WordPress nav loop
- You do not have permission to create Navigation Menus – Twenty Twenty-Two theme
- Creating a navigation menu to see where you are on your website
- current-menu-item class is not added
- Automatically list top level menu item child pages
- Check if menu_item has children or has parent
- Replace a menu with widget or a custom template file programmatically
- wp_page_menu not working right?
- How can I add text to a single nav menu item?
- Alternative to wp_get_nav_menu_items?
- Using my WordPress menu on another platform
- How Do I Add Images To Main Navigation Menu
- Add a submenu to wp_nav_menu
- Walker menu not displaying at all
- Hide menu from homepage
- remove menu items if user can’t read
- add_filter for where statment issue
- Is there a hook for nav menu item links to add custom css programatically?
- How to add css to single navigation text? [closed]
- My navigation menu isn’t working. What happened? Please help!
- How to automatically redirect to first item of second navigation level in a multi-level menu?
- Locking in navigation labels before changing title?
- How to Add support for sub-menu item description in wordpress?
- Filter to hook into menu items and add a custom attribute
- Blending Foundation’s Tabs with WordPress Nav Menu & Display Active Tab
- Editing the nav menu?
- Additional navigation bar in header
- Why is my navigation in my onepage not working?
- Navigation item – current date in url
- Hide a menu (navigation bar) on all posts
- Nav Menu: Theme Location not working
- How to remove empty line space in navigation menu?
- Is it possible to get_the_post_thumbnail (Featured Image) inside a sprintf function?
- Bootstrap Theme Migrated to WordPress
- What is inside in $item in start_el function in Walker_Nav_Menu class
- Bootstrap Nav Walker Sub Menu Image
- Creating navigation out of specific IDs and their children?
- Add active class to wp_nav_menu
- Disable Top Nav Bar on Mobile
- Menu location switcher – example code fails
- how to configure this type of menu
- Header lists posts instead of showing primary nav menu
- Add Class to Custom Menu Widget ul
- Programmatically add a Navigation menu and menu items
- Site-wide tabs at WordPress website?
- Creating custom Menu for custom theme
- How to add class and span to
- Show Child of Parent Page including all other parents
- Show only second level menu items? [duplicate]
- Add item ONLY to the primairy navigation
- Image menu on responsive WordPress
- Walker for menus
- wp_nav_menu: indicate by id page grandparents
- individual images as navigation design TwentyTen
- WordPress Navigation default output
- How to call either page name as the nav link or navigation title?
- How to get wordpress navigation to work
- How do I show a different secondary navigation menu for each section of my website?
- Add a navigation menu item using MySQL
- how to make a walker to this (in bootstrap, i try but not work)
- Site navigation sits unstyled for a second on page reload [closed]
- Custom navigation / menu output (walker?)
- Navigation menu displays permalinks
- Tried to hide navigation menu on one page ended up SCRAMBLING the navigation menu on another
- Add a new menu selector element into WordPress nav-menus.php
- How to add toggle-able DOM element after nav menu item?
- Primary menu item is not highlighting when page is active even though it is linked from a url with query string to pre-populate a form field