Blog

Fixing wp_list_pages and wp_nav_menu highlighting plus breadcrumbs on Dynamic Pod Pages

Recently I took it upon myself to begin fixing what wp_list_pages and wp_nav_menu sometimes messes up — highlighting what menu/page item you’re on.

The resulting code is used on the new Pods site, and it’s really only basic (wp_list_pages is basic in itself, while wp_nav_menu I’m only focusing on the ‘menu-‘ classes. It covers whenever you’re on a URL that isn’t in WP (dynamic pod pages, 404s, etc) but matches items in the menu / pages list. Why wp_nav_menu doesn’t specifically look at the current URL itself is beyond me, but oh well 🙂

Pop this code into your theme functions.php file and you should be all set:

http://pastebin.com/YXAcwEXm

Along the same lines, here’s a handy breadcrumb fixer (example uses yoast_breadcrumb from the WordPress SEO by Yoast plugin):

http://pastebin.com/NrX70YRC

The code above only goes two levels deep (like cool-stuff/*/*) and in the case of the second level, be sure to supply a field name in your $pods->parent variable to go off of to get the related name that’s called via $pods->get_field(‘parent_field_name.name’) in the breadcrumb fixer.

Thinking about adding this into Pods 2.0 core either as a component you can enable or have it just run with an option to disable it with a hook.