How does a minimal menu walker look like?

You could create a very simple walker, like this one. To detect the current item, inspect $item->current. It is TRUE for the current item only. I wouldn’t add a class, but deactivate the useless link completely, because it doesn’t have to be clickable anyway. Example: class One_Line_Walker extends Walker { public function walk( $elements, $max_depth … Read more

Comment Walker vs. Comment Callback

We could rewrite: wp_list_comments( array( ‘callback’ => ‘bootstrap_comment_callback’, )); with the null walker parameter: wp_list_comments( array( ‘walker’ => null, ‘callback’ => ‘bootstrap_comment_callback’, )); which means we are using the default Walker_Comment class: wp_list_comments( array( ‘walker’ => new Walker_Comment, ‘callback’ => ‘bootstrap_comment_callback’, )); The Walker_Comment::start_el() method is just a wrapper for one of these protected methods: … Read more

Add Caret to Menu Items with Sub-Menus in WordPress Theme

I do this using jQuery (since it doesn’t necessarily need to be in the TEXT (for screen readers, etc.) – just another option…: jQuery(document).ready(function() { jQuery(‘ul#nav li’).has(‘ul’).addClass(‘parentul’); }); Then for that “parentul” class I put in a background image of an arrow and position it to the right > …

How Does The Walker Class Work?

I searched and read about the walker class. I ran tests, I played around with the code and I finally understood. I hope this can be helpful to others too. You’ll need to implement the walker class for this. Here is a simple example. $defaults = array( ‘theme_location’ => ‘primary’, ‘container’ => ‘ul’, ‘menu_class’ => … Read more

How to count nav menu items?

Call wp_get_nav_menu_object to get a menu object, which will give you the count of items for that menu. Example: // Get menu object $my_menu = wp_get_nav_menu_object( ‘your-menu-name-or-slug’ ); // Echo count of items in menu echo $my_menu->count; Hope that helps.

Mega Menu Walker

If I understand the problem setup correctly, you could try to do the break and widget class counting within the wp_nav_menu_objects filter. Here’s an updated example, it’s rather expanded because of the extra debug part: add_filter( ‘wp_nav_menu_objects’, function( $items, $args ) { // Only apply this for the ‘primary’ menu: if( ‘primary’ !== $args->theme_location ) … Read more