Forked from gerbenvandijk/Mark parent navigation active when on custom post type single page
          
        
    
          Last active
          February 20, 2018 09:15 
        
      - 
      
 - 
        
Save samuelcotterall/b252160874b99f4faee65a25fa1b4316 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
samuelcotterall revised this gist
Jan 7, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ // Getting the post type of the current post $current_post_type = get_post_type_object(get_post_type($post->ID)); $current_post_type_slug = $current_post_type->rewrite['slug']; // Getting the URL of the menu item $menu_slug = strtolower(trim($item->url));  - 
        
Gerben van Dijk renamed this gist
Jun 12, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. - 
        
Gerben van Dijk renamed this gist
Mar 27, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. - 
        
Gerben van Dijk revised this gist
Mar 27, 2013 . No changes.There are no files selected for viewing
 - 
        
Gerben van Dijk revised this gist
Mar 27, 2013 . No changes.There are no files selected for viewing
 - 
        
Gerben van Dijk created this gist
Mar 27, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ <?php add_action('nav_menu_css_class', 'add_current_nav_class', 10, 2 ); function add_current_nav_class($classes, $item) { // Getting the current post details global $post; // Getting the post type of the current post $current_post_type = get_post_type_object(get_post_type($post->ID)); $current_post_type_slug = $current_post_type->rewrite[slug]; // Getting the URL of the menu item $menu_slug = strtolower(trim($item->url)); // If the menu item URL contains the current post types slug add the current-menu-item class if (strpos($menu_slug,$current_post_type_slug) !== false) { $classes[] = 'current-menu-item'; } // Return the corrected set of classes to be added to the menu item return $classes; } ?>