Add Current Class To Single Posts in Wordpress Nav Menu


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.