Adding current menu item class to customised Buddypress menu
-
Hi,
mercime ( @mercime) kindly posted the following function that hides the nav items for Buddypress pages when users are logged out:
add_filter( 'wp_nav_menu_items', 'mme_loggedin_only_links' ); function mme_loggedin_only_links($items) { if (!is_user_logged_in()) return $items; else $ouractivity = '<li><a href="' . home_url('/') . 'activity' . '">' . __('Activity', 'buddypress' ) . '</a></li>'; $ourmembers = '<li><a href="' . home_url('/') . 'members' . '">' . __('Members', 'buddypress' ) . '</a></li>'; $ourgroups = '<li><a href="' . home_url('/') . 'groups' . '">' . __('Groups', 'buddypress' ) . '</a></li>'; $ourgroupforums = '<li><a href="' . home_url('/') . 'forums' . '">' . __('Forums', 'buddypress' ) . '</a></li>'; $items = $items . $ouractivity; $items = $items . $ourmembers; $items = $items . $ourgroups; $items = $items . $ourgroupforums; return $items; }
I would now like to extend this function so that classes that are added to the nav items in the standard WordPress menu are also added to the BuddyPress nav items. For instance, the classes added to my home navigation tab are “menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-18 current_page_item” when the page is active. I am particularly keen to have a class for current-menu-item added to each of the four BuddyPress pages when they are active.
Could someone help adapt the function above so that such a class is added?
Thanks,
Nick
- The topic ‘Adding current menu item class to customised Buddypress menu’ is closed to new replies.