Adding Static Menu Items to wp_nav_menu()

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 wp_nav_menu()‘s items_wrap parameter.

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 wp_nav_menu():

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.

Tools

This essay was written in early 2013 to be my contribution to Tim Smith’s Lustra Magazine. Unfortunately, circumstances dictated that the project never launched and this has been sitting in my Documents folder ever since. I ran across it today and wanted to share. Enjoy. We’re lucky folks. By our industry’s very nature, the toolsets […]

Keep reading »

Responsive, Flexible-Height Sticky Footers in CSS

Since I’ve been in the game, front-end devs have been wrestling with sticky footers like it was going out of style. I’m no exception, but today I learned a trick that made things a lot easier. Before we go on though, I’d like to explain the problem briefly. It’s common for websites to have a […]

Keep reading »

HTML to Markdown Converter

While I was migrating my blog, I ran across the need to convert my HTML-formatted posts to Markdown. Surprisingly, there are few good tools to do this quickly, but the best I found was to-markdown.js by Dom Christie.

The only weird thing about his app is for some reason he seems to have copying disabled in the Markdown output box. It looks like Dom has reworked the app a bit and this has been fixed.