Created
April 5, 2019 10:02
Star
You must be signed in to star a gist
Add top level menu active menu class to child pages without adding submenu level in admin panel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function additional_active_item_classes( $classes = array(), $menu_item = false ) { | |
// custom taxonomy | |
if ( $menu_item->title == 'Custom Tax Name Page' && is_tax('custom_tax') ) { | |
$classes[] = 'current-menu-item'; | |
} | |
// custom post type single | |
if ( $menu_item->title == 'Custom Post Type Page' && is_singular('products') ) { | |
$classes[] = 'current-menu-item'; | |
} | |
// blog post single | |
if ( $menu_item->title == 'Blog Page' && is_singular('post') ) { | |
$classes[] = 'current-menu-item'; | |
} | |
return $classes; | |
} | |
add_filter( 'nav_menu_css_class', 'additional_active_item_classes', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment