4

Please tell my what is 10, 2 in below mention code:

add_filter('nav_menu_css_class', 'add_active_class', 10, 2 );

function add_active_class($classes, $item) {

if($item->menu_item_parent == 0 && in_array('current-menu-item', $classes)) {

    $classes[] = "active";

}

return $classes;

}
  • Some time ago, I tried to draw a schematic image of this, I don't know if it's helpful to you, but you can check it out here – birgire Sep 28 '13 at 11:20
7

Have a look at the codex page for add_filter.

The 10 is the $priority parameter (10 is default) which defines when your function will run in regards to the other functions which are attached to the nav_menu_css_class filter. 2 is the $accepted_args parameter which tells wordpress how many parameters the function you want to add will take. In this case your add_active_class function can take 2 parameters ($classes and $item).

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.