$args->has_children not working with start_el()

I just resolved this issue! Woo hoo! The thing is that using var_dump($args) shows a lot stuff like so: object(stdClass)#152 (16) { [“menu”]=> object(WP_Term)#145 (10) { [“term_id”]=> int(2) [“name”]=> string(9) “Main menu” [“slug”]=> string(9) “main-menu” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(2) [“taxonomy”]=> string(8) “nav_menu” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(12) [“filter”]=> string(3) “raw” } [“container”]=> string(0) … Read more

Walker gives additional taxonomy name?

Edit: After looking at the wp_list_categories() code I noticed that you can just pass a class parameter to the function. If you pass an empty string, the built-in Walker will always echo class=””. To get rid of the class attribute entirely, you will still have to use a custom walker and edit start_el: function start_el( … Read more

Menu location by menu id or menu ID in start_el() Walker

You’ll find it much easier to control which fields are shown, by controlling which walker is used. Rather than trying to ‘toggle’ the fields inside the walker. I also wanted to show a bunch of custom fields, and only show them on a menu at a particular menu location. So I used the following… add_filter( … Read more

Adding ul class with wp_list_categories Custom Walker

You should be extending Walker_Category not the main Walker class. class Walker_Simple_Example extends Walker_Category { function start_lvl(&$output, $depth=1, $args=array()) { $output .= “\n<ul class=\”product_cats\”>\n”; } function end_lvl(&$output, $depth=0, $args=array()) { $output .= “</ul>\n”; } function start_el(&$output, $item, $depth=0, $args=array()) { $output .= “<li class=\”item\”>”.esc_attr( $item->name ); } function end_el(&$output, $item, $depth=0, $args=array()) { $output .= … Read more

Incrementing a class in a custom walker

Use a class variable to keep the ‘index’ of the colour you wish to display. Increment each time it’s used, and check if it goes over, in which case set it back to 1. class Salamander_Advent_Walker extends Walker_page { private $color_idx = 1; function start_el(&$output, $item, $depth, $args) { if ( $depth ) { $indent … Read more

Why is my menu order not working with wp_nav_menu?

AFAIK there’s a non-documented orderby parameter, that can be set to menu_order. Edit: Straight from core, inside /wp-includes/nav-menu-template.php Line# 195 (WP 3.3.1): $sorted_menu_items = array(); foreach ( (array) $menu_items as $key => $menu_item ) $sorted_menu_items[$menu_item->menu_order] = $menu_item; It’s the lines immediately before the Walker runs. So the set menu_order should affect the order. You’ll just … 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