WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been using the nav_menu_css_class filter in one of my plugins, implemented as:

add_filter( 'nav_menu_css_class', 'wbwcrf_nav_menu_css_class', 10, 3 );
function wbwcrf_nav_menu_css_class( $classes, $item, $args )
    /* snip */
    return $classes;

The filter clearly has 3 arguments in the code (source) yet someone using my plugin has told me they get the error Warning: Missing argument 3 for wbwcrf_nav_menu_css_class().

So I looked at the codex documentation on nav_menu_css_class which has an example using 2 arguments, I changed my code to 2 arguments since I'm not actually using the $args argument and everything seems to be working fine.

But I'm still really stumped as to why the source has 3 arguments yet the codex has 2 and why I don't receive any error when using 3 arguments, yet someone using my plugin does. Anyone able to clear up my confusion here please?

share|improve this question
up vote 3 down vote accepted

I can confirm that this filter applied with 3 parameters as you mentioned in your snippet. The warning is very strange and shouldn't appear if WordPress core wan't hacked.

The best practice for this case is to request parameters, which are required by your hook. So if you don't use $args, so don't request it:

add_filter( 'nav_menu_css_class', 'wbwcrf_nav_menu_css_class', 10, 2 );
function wbwcrf_nav_menu_css_class( $classes, $item ) 
    // ...

Another approach is to set default values for income arguments:

add_filter( 'nav_menu_css_class', 'wbwcrf_nav_menu_css_class', 10, 3 );
function wbwcrf_nav_menu_css_class( $classes, $item, $args = array() ) 
    // ...
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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