bp_core_new_nav_item()

Description Description

Adds a navigation item to the main navigation array used in BuddyPress themes.

Top ↑

Example Usage Example Usage

The snippet below is taken from bp-messages.php, and is used to add the main “Messages” link to the user navigation.
[sourcecode language=”php”]
bp_core_new_nav_item(
array(
‘name’ => __(‘Messages’, ‘buddypress’),
‘slug’ => $bp->messages->slug,
‘position’ => 50,
‘show_for_displayed_user’ => false,
‘screen_function’ => ‘messages_screen_inbox’,
‘default_subnav_slug’ => ‘inbox’,
‘item_css_id’ => $bp->messages->id
));
[/sourcecode]

As you can see above, this menu item is not displayed when viewing another users profile, it will call the ‘messages_screen_inbox’ function when clicked, and will take you to your ‘inbox’ sub navigation when clicked. It is also given the ID of the internal core component set from within BuddyPress, so that it can be styled later with an icon.

Top ↑

Parameters Parameters

name
String | Required | The display name for the navigation item.

slug
String | Required | The URL slug for the navigation item.

item_css_id
String | Optional/Recommended | Default: FALSE | The ID to give the navigation item in HTML for CSS styling.

show_for_displayed_user
Boolean | Optional | Default: TRUE | Determines if this navigation item appears when viewing another users profile.

site_admin_only
Boolean | Optional | Default: FALSE | Set to TRUE if a menu item is only to be seen by site admins (See is_site_admin())

position
Integer | Optional | Default: 99 | Index of where this navigation item appears in the list. Lower numbers appear sooner than higher numbers.

screen_function
String | Optional | Default: FALSE | Name of function to run when the navigation item is clicked.

default_subnav_slug
String | Required | Sets which sub navigation item is selected when this root navigation item is clicked. If you do not have sub navigation – use the same value used for slug.

Top ↑

Notes Notes

It’s important to note that if either the ‘slug’ or the ‘name’ are omitted, this function will return false and no menu item will be created.

This function replaces bp_core_add_nav_item(), which was deprecated in BuddyPress 1.1.

Top ↑

  • bp_core_remove_nav_item()
  • bp_core_sort_nav_items() – deprecated since 2.6
  • bp_core_new_subnav_item()
  • bp_core_sort_subnav_items() – deprecated since 2.6
  • bp_core_remove_subnav_item()
  • bp_core_reset_subnav_items()

Source File

bp_core_new_nav_item() is located in bp-core/bp-core-buddybar.php