7

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;

}
1
  • 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
    Commented Sep 28, 2013 at 11:20

1 Answer 1

11

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 and acknowledge you have read our privacy policy.

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