0
votes

I have created a custom post type 'presentations' and I have adding the archive page in my main menu. My hierarchy menu is :

Meetings (empty link : href="#")

—— Companies (empty link : href="#")

—— —— Presentations (CPT archive page)

I would like to add classes 'current-menu-ancestor' and 'current-menu-parent', as follows :

Meetings (empty link : href="#") 'current-menu-ancestor'

—— Société (empty link : href="#") 'current-menu-parent'

—— —— Présentations (CPT archive page) current menu

How can I do this? Thanks

1

1 Answers

0
votes

Not sure it's that what exactly you looking for but you can modify this to make conditions right for you. Try to print_r(); for $classes , $item, $args.

Also, check Codex references

function filter_handler( $classes , $item, $args, $depth ){ 
    if (in_array('current-menu-item', $item->classes) OR in_array('current_page_item', $item->classes)) {
        if ( 'presentations' == get_post_type() ) {
            if ( $depth == 0 ) {
                $classes[] = 'current-menu-ancestor';
            }
            if ( $depth == 1 ) {
                $classes[] = 'current-menu-parent';
            }
            if ( $depth == 2 ) {
                $classes[] = 'current-menu';
            }
        }
    }
    return $classes;
}
add_filter( 'nav_menu_css_class', 'filter_handler', 10, 4 );