Pass a parameter to a menu walker

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=”” ) { … Read more

Using string instead of object class instantiation on the walker argument breaks wp_nav_menu

Apparently custom nav menu walkers are not supported though they were supposed to be. I’m surprised this only has been discovered now. However, there is an easy fix for you to get them to work. Just add this to your theme: add_filter( ‘wp_nav_menu_args’, function( $args ) { if ( isset( $args[‘walker’] ) && is_string( $args[‘walker’] … 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

Add Page ID class to nav menu items

We can add custom nav menu classes through the nav_menu_css_class filter. Example: The following should add the CSS class wpse-object-id-{object_id} to the <li> tags: // Add filter add_filter( ‘nav_menu_css_class’, ‘wpse_menu_item_id_class’, 10, 2 ); // Your navigational menu wp_nav_menu( $args ); // Remove filter remove_filter( ‘nav_menu_css_class’, ‘wpse_menu_item_id_class’, 10, 2 ); where we define the filter callback … Read more

Custom Nav Walker menu – Display children count

I sort of added onto @Giri’s answer by using array_map and array_count_values. if this helps anyone in the future. I didn’t wish to use a counter and a foreach loop for something so simple. function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { if ($item->hasChildren) { $locations = get_nav_menu_locations(); … Read more

Admin Panel – Disable Moving Selected Terms To Top of Metabox

Try adding this in your functions.php file: // Let’s stop WordPress re-ordering my categories/taxonomies when I select them function stop_reordering_my_categories($args) { $args[‘checked_ontop’] = false; return $args; } // Let’s initiate it by hooking into the Terms Checklist arguments with our function above add_filter(‘wp_terms_checklist_args’,’stop_reordering_my_categories’);

How do I pass an argument to my custom walker?

Native walker are triggered with walk() method and are not set up to receive data on creation. You can define custom property and constructor method for this purpose: class plus_walker extends Walker_Nav_Menu { var $refine; function __construct($refine) { $this->refine = $refine; } } //stuff ‘walker’ => new plus_walker(‘review’); After this you can access your custom … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)