Benefits of using Nav Walker?

Are there any benefits to using a nav walker class over iterating through wp_get_nav_menu_items()?

Nav walkers seem very clunky to me and iterating over an array feels easier and more re-usable but it then bypasses the internal menu filters of wordpress that I don’t know much about. Will this make my theme incompatible with some plugins?

Best practice advice here would be greatly appreciated.

3 Answers
3

I would say mostly you see the usage of wp_nav_menu(), which does use wp_get_nav_menu_items(). You can use wp_nav_menu() with the default walker or a custom walker.

To be honest I can’t remember the time I did a menu manually, with wp_get_nav_menu_items() or something else, and I tend to be lazy, so this is definitely more work.

The Walker Class gives you a lot of possibilities as there is more information available, which definitely is big plus. So whether you should leverage a walker – or otherwise (I’d say) use wp_nav_menu() – is pretty much a question of what you need to achieve, for more complex menus I personally would always go with a walker. Last but not least, walkers are nicely reusable, which is pretty neat and another plus.

Leave a Comment