-
-
Save billerickson/166aba8ca0a41989a432 to your computer and use it in GitHub Desktop.
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 | |
/* | |
* Customize Menu Item Classes | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/customize-which-menu-item-is-marked-active/ | |
* | |
* @param array $classes, current menu classes | |
* @param object $item, current menu item | |
* @param object $args, menu arguments | |
* @return array $classes | |
*/ | |
function be_menu_item_classes( $classes, $item, $args ) { | |
if( 'header' !== $args->theme_location ) | |
return $classes; | |
if( ( is_singular( 'post' ) || is_category() || is_tag() ) && 'Blog' == $item->title ) | |
$classes[] = 'current-menu-item'; | |
if( ( is_singular( 'code' ) || is_tax( 'code-tag' ) ) && 'Code' == $item->title ) | |
$classes[] = 'current-menu-item'; | |
if( is_singular( 'projects' ) && 'Case Studies' == $item->title ) | |
$classes[] = 'current-menu-item'; | |
return array_unique( $classes ); | |
} | |
add_filter( 'nav_menu_css_class', 'be_menu_item_classes', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment