1

I extended Walker_Nav_Menu class as below

class YPE_custom_navwalker extends Walker_Nav_Menu{}

I want use the get_number_of_root_elements( $elements ) function that place in to Walker class within my new class YPE_custom_navwalker

i want use that function for showing the number of root elements within start_el function i used this code below but don't work

echo $args->walker->get_number_of_root_elements($elements);
| improve this question | | | | |
2

I'm not sure if this is what you're after. You can use $this to reference the current walker instance.

class YPE_custom_navwalker extends Walker_Nav_Menu {
    public function start_lvl(&$output, $depth=0, $args=array()) {

        $items = wp_get_nav_menu_items( $args->menu->term_id );
        echo $this->get_number_of_root_elements( $items );

        parent::start_lvl(&$output, $depth,$args);
    }
}
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.