Skip to:
Content
Pages
Categories
Search
Top
Bottom
Codex HomeDeveloper ResourcesFunction ExamplesCore Component → bp_core_new_nav_item()

bp_core_new_nav_item()

Description

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

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.

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.

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.

Source File

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

Skip to toolbar