wp_nav_menu_items and current class
-
I’ve added a function which adds a menu item (Mail) to my nav menu. I did this because I couldn’t figure out a way to do it via the GUI.
While the menu item works, I’m unable to get it to acquire the current class. The menu item doesn’t change it’s appearance when it’s active/current.
// Adds Mail with counter to header menu function my_nav_menu_positioned_msgs_counter( $menu, $args ) { $msg_url = bp_core_get_user_domain(bp_loggedin_user_id()) .'messages/'; $user=wp_get_current_user(); $name=$user->display_name; if (!is_user_logged_in()) return $menu; else $int = bp_get_total_unread_messages_count(); if( $args->theme_location == 'Header Menu' ) // only for primary menu { $menu_array = array(); while ( false !== ( $item_pos = strpos ( $menu, '<li', 3) ) ) { $menu_array[] = substr($menu, 0, $item_pos); $menu = substr($menu, $item_pos); } $menu_array[] = $menu; array_splice($menu_array, 3, 0, '<li><a href=" ' .$msg_url. ' " title="Read or compose private messages"><p style="font-weight:bold;">Mail <span class="badge">'.bp_get_total_unread_messages_count( bp_loggedin_user_id()).'</span></p></a></li>'); // 0,0 is first position, 1,0 is second, etc $menu = implode('', $menu_array); } return $menu; } add_filter('wp_nav_menu_items','my_nav_menu_positioned_msgs_counter', 10, 2);
Is there a simple fix for this? I’ve read other similar posts, but I couldn’t find anything that worked for my situation.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘wp_nav_menu_items and current class’ is closed to new replies.