Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding current menu item class to customised Buddypress menu

  • Avatar of nickharambee
    nickharambee
    Participant

    @nickharambee

    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 = ‘

  • ‘ . __(‘Activity’, ‘buddypress’ ) . ‘
  • ‘;
    $ourmembers = ‘

  • ‘ . __(‘Members’, ‘buddypress’ ) . ‘
  • ‘;
    $ourgroups = ‘

  • ‘ . __(‘Groups’, ‘buddypress’ ) . ‘
  • ‘;
    $ourgroupforums = ‘

  • ‘ . __(‘Forums’, ‘buddypress’ ) . ‘
  • ‘;
    $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

You must be logged in to reply to this topic.