bp_nav_menu_get_item_url( string $slug )

Get the URL for a BuddyPress WP nav menu item, based on slug.

Description

BuddyPress-specific WP nav menu items have dynamically generated URLs, based on the identity of the current user. This function lets you fetch the proper URL for a given nav item slug (such as ‘login’ or ‘messages’).

Parameters

$slug

(string) (Required) The slug of the nav item: login, register, or one of the slugs from the members navigation.

Return

(string) $nav_item_url The URL generated for the current user.

Source

File: bp-core/bp-core-functions.php

function bp_nav_menu_get_item_url( $slug ) {
	$nav_item_url   = '';
	$nav_menu_items = bp_nav_menu_get_loggedin_pages();

	if ( isset( $nav_menu_items[ $slug ] ) ) {
		$nav_item_url = $nav_menu_items[ $slug ]->guid;
	}

	return $nav_item_url;
}

Changelog

Changelog
Version Description
BuddyPress 1.9.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.