Posted By

inflightatnight on 10/25/11


Tagged

php wordpress filter


Versions (?)

Add Current Class To Single Posts in Wordpress Nav Menu


 / Published in: PHP
 

URL: http://wordpress.stackexchange.com/questions/3014/highlighting-wp-nav-menu-ancestor-class-w-o-children-in-nav-structure

Add current class to single posts in Wordpres wpnavmenu by adding a filter

  1. add_filter('nav_menu_css_class', 'current_type_nav_class', 10, 2 );
  2. function current_type_nav_class($classes, $item) {
  3. $post_type = get_query_var('post_type');
  4. if ($item->attr_title != '' && $item->attr_title == $post_type) {
  5. array_push($classes, 'current-menu-item');
  6. };
  7. return $classes;
  8. }

Report this snippet  

You need to login to post a comment.