This week I found myself needing to append a static menu item to the end of a
wp_nav_menu()-powered navigation menu. After a bit of Googling, I discovered I could do this using
It’s actually pretty simple. Create a function that picks apart the default value of
items_wrap and rebuilds it with a static link. Then call that function in the
items_wrap parameter of
How would something like that be useful? In my case, I was adding a WooCommerce cart link to the navigation that dynamically pulled in the sub-total. My code looked something like this:
You can even check for certain conditions, and only return the static menu item along with the default items if the those conditions are true.
Here, I’m checking to see if there are items in the WooCommerce cart, and if there are, I’m adding a link to the cart to the nav menu.