Custom Links in Walker Class

Test for … $item->object=”custom” This is used for custom links only. $item->object is always the post type or the item type (category for example). Not sure what happens when someone registers a custom post type named custom 🙂

Use wp_nav_menu to dynamically generate child menus

My solution uses the Walker_Nav_Menu and a custom class and is mostly hacked together from this post: How do I dynamically populate wp_nav_menu from a custom taxonomy? Solution: //define the custom post type //could use “page” or “post” as well. define(“MENU_CPT”, “action”); //custom function for selecting posts based on a page parent (ne’ term_id) function … Read more

Walker for menus

All of the methods are being overridden when you load your own walker, but typically you would extend another Walker which works a bit like “filtering” or “pluggable functions”. Take a look at this very simple walker from another question: class my_extended_walker extends Walker_Nav_Menu { function start_lvl(&$output, $depth = 0, $args = array()) { $output … Read more

Determine if a navigation item has children

You can filter wp_nav_menu_objects and add the classes in one rush. You don’t even need a custom walker for that. add_filter( ‘wp_nav_menu_objects’, ‘add_has_children_to_nav_items’ ); function add_has_children_to_nav_items( $items ) { $parents = wp_list_pluck( $items, ‘menu_item_parent’); foreach ( $items as $item ) in_array( $item->ID, $parents ) && $item->classes[] = ‘has-children’; return $items; } The class has-children will … Read more

Using Different nav_menu_css_class for different nav_walkers

The third parameter passed into nav_menu_css_classes should give you the information you need to sort out the different menus. Try: function onpage_nav_menu_css_class($classes, $item, $args) { var_dump($args); return $classes; } add_filter(‘nav_menu_css_class’, ‘onpage_nav_menu_css_class’, 1, 3); Note: That will make a mess of your page. It is debugging/development only code. I think that the theme_location should be sufficient … Read more