nav_menu_css_class filter #79

Closed
Vinsanity opened this Issue Jul 24, 2012 · 2 comments

Comments

Projects
None yet
2 participants

add_filter('nav_menu_css_class' , function ($classes, $item){
if($item->current == 1){ //Notice you can change the conditional from is_single() and $item->title
$classes[] = "active";
}
return $classes;
} , 10 , 2);

This function was giving me some trouble today. I was not able to activate or preview this theme unless I commented this out in the functions.php file. Any ideas? Can the function be written in place of the param looking for a function name or does nav_menu_objects only support that?

Owner

milohuang commented Jul 24, 2012

Change it to the below and see if it works. We are using the recommended WP API (http://codex.wordpress.org/Plugin_API/Filter_Reference/nav_menu_css_class).

function reverie_active_nav_class( $classes, $item )
{
    if($item->current == 1)
    {
        $classes[] = 'active';
    }
    return $classes;
}
add_filter( 'nav_menu_css_class', 'reverie_active_nav_class', 10, 2 );

Yes changing it to the standard API for this filter worked. Thanks!

But my original question was in regards the function itself being written into the callback parameter of the add_filter() function. I know that the recommended API allows for an anonymous function to be passed in for the callback but the nav_menu_css_class filter reference API does not show this as an example.

I'm wondering if there is an issue with that filter specifically (more of a question for WP staff I guess)?

Could also just be a quirk in this instance of my WP install (most likely, this is the issue). Too many variables...

Anyway, great framework, thanks for distributing it!

@milohuang milohuang closed this Jan 11, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment