Created
October 7, 2013 11:49
-
-
Save rfvcorreia/6866541 to your computer and use it in GitHub Desktop.
Fix CPT Menu highlight
This file contains hidden or 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
| //Fix CPT menu highlight | |
| add_filter( 'nav_menu_css_class', 'namespace_menu_classes', 10, 2 ); | |
| function namespace_menu_classes( $classes , $item ){ | |
| $Cpost = 'portfolio'; //Define CPT name | |
| $CpostMenu = get_bloginfo('url').'/'.$Cpost.'/'; //Define CPT Menu URL | |
| if ( get_post_type() == $Cpost || is_archive( $Cpost ) ) { | |
| // remove that unwanted classes if it's found | |
| $classes = str_replace( 'current-page-parent', '', $classes ); | |
| // find the url you want and add the class you want | |
| if ( $item->url == $CpostMenu ) { | |
| $classes = str_replace( 'menu-item', 'menu-item current-menu-item', $classes ); | |
| remove_filter( 'nav_menu_css_class', 'namespace_menu_classes', 10, 2 ); | |
| } | |
| } | |
| return $classes; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment