Custom walker
-
Hello Tracey,
Is it possible to build in a way, so we can extend the wp_nav?
In other words, can we extend the function widget and replace the wp_nav with a custom one:wp_nav_menu( array( 'menu' => '', 'container' => false, 'fallback_cb' => false, 'items_wrap' => '%3$s', 'depth' => 0, 'walker' => new my_page_menu ) );This would be awesome.
-
I currently don’t have plans to do this. Can you explain what problem you’re trying solve so I can better understand why you want this functionality.
With this function i can build custom menu’s. Think about adding a img with the title of the item.
I am using this on difference sites. Because this plugins works good. 😉
Maybe you can you use the extend tool? So i can extend it in the template.Hello Tracey,
Got a update for this. I edited your code to add a custom walker.
I will share the code, maybe other people are happy to use it.File: better-menu-widget.php, line 86 -91;
wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu, 'menu_class' => esc_attr( $instance['menu_class'] ), 'container' => false ) );Replace with:
if ( has_filter('better_menu_walker')) { apply_filters('better_menu_walker', $instance, $nav_menu); } else { wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu, 'menu_class' => esc_attr( $instance['menu_class'] ), 'container' => false ) ); }Then you can it in another file with:
function better_menu_walker_widget ( $instance, $nav_menu ) { wp_nav_menu( array( 'fallback_cb' => false, 'menu' => $nav_menu, 'menu_class' => esc_attr( $instance['menu_class'] ), 'container' => false, 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s<a class="hamburger" href="#" title="Open / Close Menu"><span>hamburger</span><div></div></a></ul>', 'depth' => 0 ) ); } add_filter('better_menu_walker', 'better_menu_walker_widget', 1, 2);or use it like:
function better_menu_walker_widget ( $instance, $nav_menu ) { wp_nav_menu( array( 'menu' => $nav_menu, 'container' => false, 'fallback_cb' => false, 'items_wrap' => '%3$s', 'depth' => 0, 'walker' => new my_new_nav_page_menu ) ); } add_filter('better_menu_walker', 'better_menu_walker_widget', 1, 2);If you could add this, then this plugin is really great.
Thanks for the code. I’ll take a look at as soon I get some down time.
The topic ‘Custom walker’ is closed to new replies.