bp_core_new_nav_item()

Codex HomeDeveloper DocsFunction ReferenceCore Component → bp_core_new_nav_item()

Description

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

↑ Table of Contents ↑

Example Usage

The snippet below is taken from bp-messages.php, and is used to add the main “Messages” link to the user navigation.

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
	));

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.

↑ Table of Contents ↑

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 | Optional/Recommended | Default: FALSE | Sets which sub navigation item is selected when this root navigation item is clicked.

↑ Table of Contents ↑

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.

↑ Table of Contents ↑

  • bp_core_remove_nav_item()
  • bp_core_sort_nav_items()
  • bp_core_new_subnav_item()
  • bp_core_sort_subnav_items()
  • bp_core_remove_subnav_item()
  • bp_core_reset_subnav_items()

Last updated by John James Jacoby on September 2, 2009 – 4:00pm EST