you can always search & replace by string or regex the output html of the filtered $items.
anyway, if you’re targeting usual menu items, you can add $post objects and order items through the wp_nav_menu_objects filter, otherwise here’s the basic sample code:
function replace_itemcart_in_menu( $items, $args ) {
$url = home_url('my-item');
$previtem = '<li id="menu-item-11" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-11"><a href="'.$carturl."https://wordpress.stackexchange.com/">My Item</a>';
$newitem = '<li>New Item</li>';
$items = str_replace($previtem, $previtem.$newitem, $items);
return $items;
}
Related Posts:
- Dynamically exclude menu items from wp_nav_menu
- Add custom menu item using wp_nav_menu_items filter
- Custom search filter causes menu and query_posts problems
- Unregister Nav Menu from Child-Theme
- Allow html tags in WordPress Custom Menus Description Field
- Using filters to change href of nav menu page link
- How to apply a class to the second word in menu list item?
- WordPress nav_menu_link_attributes Not Working
- Is it possible to add a filter for the output of nav-menu items in admin?
- if role is logged in then do something
- Filter menu item to add classes/attributes?
- Edit html for menu items in default frontend menu
- When at / ( or “home”) my menu doesn’t get a current-menu-item class
- How to add parent element’s title to nav menu’s child?
- Why is ‘nav_menu_item_args’ filter’s $item argument empty?
- Add class to active element and its parent in nav menu
- display only the wp_nav_menu, which has the current-menu-item
- Removing strip_tags not working on nav_menu_description
- Third level navigation class
- How to add #navbar to all page links?
- add span to top level links of a wordpress menu called “main”
- Debugging – trying to add search box to menus
- wp_list_pages() but only show children on the branch you are on
- From a page, is it possible to find entry’s “menu_item_parent”?
- Add active class to top-level menu items when viewing single for that post type
- add_filter on menu items to add a menu item
- how to disable default menu classes
- Insert other menus as submenus of a main menu
- list category posts under its item in menu
- Prevent menu from loading in a page template [duplicate]
- Insert a div before the wp_nav_menu
- How to change menu structure?
- Secondary Navigation Menudisappeared When using wp_nav_menu_items
- remove specific classes from menu items
- wp_nav_menu action/filter help
- add_filter for where statment issue
- Add a counter beside menu item label
- Add custom link on the fly to nav menu
- menu-item class missing on wordpress menu
- Filter to hook into menu items and add a custom attribute
- if role is logged in then do something
- Possible to append class to nav menu added to widget area?
- Modifying Woocommerce menu based on tags and categories
- Why does WordPress convert absolute URLs to relative URLs for menu items?
- Menu location switcher – example code fails
- Add Featured Image and Title to wp_nav_menu items
- Show thumbnail to category items in wp_nav_menu(), how?
- Add Class to Custom Menu Widget ul
- Avoid changing menu query with suppress_filters => false
- Removing menu item doesn’t get removed on edit post
- Add Protocol to Custom Menus
- How to modify menu text in callback function of ‘walker_nav_menu_start_el’ hook
- Why is WordPress stripping anchor links from mneu item URLs?
- Add button and title on submenu WordPress
- In WordPress, I want to use code to filter out one menu item (page) from displaying when I call wp_nav_menu() function
- How to Hard Code Custom menu items
- Check if page is in a certain menu
- Increase search results for Admin -> Appearance -> Menus -> Search (default is 10)
- How do I add the data-toggle=”modal” data-target=”#myModal” attribures to a WP Nav bar?
- Page not appearing in navigation bar
- Add an extra field to the navigation menu box?
- Adding custom text in items titles from wp_nav_menu()
- Why do the menu titles change with the renaming of pages?
- get menu id using its name
- Force PDF download from custom menu?
- Make menu bootstrap compatible
- WordPress sub-menu items suddenly not showing
- WordPress get or set active menu class
- switch_to_blog() and wp_nav_menu() not functioning properly
- Get latest posts from WordPress site without header, menu and sidebar
- How to add ID attribute to each submenu?
- How do you link to a place in another page without any styling issues?
- Determine the last child of the parent menu WP Nav Walker
- Edit menu parent element
- Navigation doesn’t render when wp is hosted
- edit user menu item
- Menu Arrow for Child Element
- Problem in applying active class to wordpress menu
- How to get submenu dropdown with images?
- Walker Class: Output Parent Description and Featured Image right after sub-menu?
- Modifying the walker to insert parent’s description above sub menus
- wp_list_pages Hierarchical Help
- How to avoid the and which added when custon menu widget is used
- How to create a complete mulilanguage site using xili language plugin?
- An alternative to WordPress’s built-in menu functionality
- pre_get_posts fix to show menu on CPT Archives broken WP 6.0
- How to link current logged-in user to their author page via URL (Beginner)
- Top bar menus not showing on mobile
- Need Help Regarding Menu Magement in admin
- And I click on a menu item and it leads me to nowhere
- Menu Responsive
- Custom menu creation
- Adding class atribute to wp_nav_menu ul
- Active menu also for single array
- Two pages named the same thing, on a different level but conflicting url paths in menus and direct links
- How do I change the default wordpress navigation header that comes with my theme?
- menu_class showing up on DIV instead of UL
- How was this menu system created?
- How can i make two menu walkers with logo in center?
- WordPress walker add class to Sub Menu a href