If child is active add class to parent in customWalker In WordPress

Im writing a customWalker for the wordpress main navigation area.

But i am a little stuck on how to find and add a class to the parent of the child which is active.

Read More

For instance

I have the whole customwalker working perfect, all parents have a active class assigned when they are active, but how to I assign an active class to the parent when a sub class is active?

I managed to assign a active class to the top depth when current_page_item was given like this:

if($depth === 0){
            $class_names = str_replace('current_page_item', 'active', $class_names);
        }

But how would I write it for a child class to show the parent an active when the child is active?

Thanks

Related posts

Leave a Reply