New answers tagged

1

If you want WordPress to add these items dynamically you would need to add a custom walker class to your menu declaration. Find where your menu is declared in the theme and add a custom walker class name in their wp_nav_menu function: wp_nav_menu( array ( 'menu'=> 'main-menu', 'container'=> '', 'walker' => new Description_Walker)); The menu may ...


0

Update - Creating a class that mimics WP_Terms and copying over the objects returned by get_the_terms() to my *_Terms class worked. Passing in the returned objects when instantiating my class hits the constructor and builds out a copy of the properties that I have control over without worrying about core code changes: $categoryTerms = ...


3

Your original solution was a hack, and no surprise it failed. In general never add methods/attributes to objects that you do not control their class and future development. The right way is to create your own object to be passed to the walker. Pass to it the category object on construction and either populate fields is a similar way to the category object ...


3

As @toscho said, you can call the walker class with parameters as you did: new BEMwalker( 'mobile' ) The constructor of BEMwalker will take the arguments (like any other function or method in PHP) so you can access the parameter(s) via $this: class BEMwalker extends Walker_Nav_Menu { private $classes; public function __construct( $classes = '' ...



Top 50 recent answers are included