Even for an adept WordPress developer, making changes in BuddyPress templates, the member components in particular, can return frustrating results. In this tutorial we will cover the basic management functions for the BuddPress Member Profiles, which include:
- BP Nav Functions
- Default BP Menu Items
- Customizing BP Profile Tabs
- Edit BP Profile Sub-Nav Items
- Adding/Removing BP Nav Menu Items
BuddyPress 1.7+ Member Profile Nav Functions
Like many other BP related code extensions, using the global $bp
within our functions is essential. A function is required for the creating or changing of the BP profile's main menu items, and a separate one for the profile's sub-menu items. All these functions have to be queued in the bp_setup_nav
action in the correct order, hence the function to create new sub-nav items for a custom main tab you create would have to run after the main tabs are created.
The Action: bp_setup_nav
The following functions will be added to the action bp_setup_nav
, with a high priority, to assure that your function runs after all the important ones for the profile nav have finished:
// Default Usage:
add_action('bp_setup_nav', $function, $priority);
// Example:
add_action('bp_setup_nav', 'add_your_custom_tabs', 151);
add_action('bp_setup_nav', 'add_your_custom_subtabs', 152);
Default BuddyPress Profile Menu Items
Modifying the main BP profile navigation tabs requires little code, and can only be done to the tabs you activated in the BuddyPress settings to prevent errors. If all your BuddyPress default components are activated, you should have the following main items in your profile (if logged in as an administrator):
- Activity
- Profile
- Sites (if on a WP multisite network)
- Messages
- Friends
- Groups
- Settings
- Forums (if BBPress forums are integrated)
To modify each nav items position or name, you would access it by its slug, which you can determine by the url after /members/username/, but the default BP nav slugs are typically a lower-case version of its name. Here the default usage:
$bp->bp_nav[$slug][$data] = $value;
Change BuddyPress Profile Menu Positions & Names
The positioning of these menu items are determined by their position number, for example, the default position of Activity
is 10
and that of Profile
is 20
. To change the default menu item positions, you can use a function similar to this:
function mb_profile_menu_tabs(){
global $bp;
$bp->bp_nav['activity']['position'] = 15;
$bp->bp_nav['messages']['position'] = 10;
}
add_action('bp_setup_nav', 'mb_profile_menu_tabs', 201);
The above code would replace the first tab from Activity to Members, and places Activity before Profile (because Profile has a position number of 20).
Changing BP Navigation Names
Similar to the above, changing the default BP profile tab names can be done by replacing the 'position' string, with 'name'. We added 3 new rows to the above function in this example:
function mb_profile_menu_tabs(){
global $bp;
$bp->bp_nav['activity']['position'] = 15;
$bp->bp_nav['messages']['position'] = 10;
$bp->bp_nav['messages']['name'] = 'Mail';
$bp->bp_nav['friends']['name'] = 'Contacts';
$bp->bp_nav['profile']['name'] = 'Account';
}
add_action('bp_setup_nav', 'mb_profile_menu_tabs', 201);
Edit BP Sub Nav Names & Positions
Editing the BuddyPress sub-menu items relies on a similar structure as their parent items, the main tabs. The significant difference here is that instead of using the bp_nav
object, we will need to use bp_options_nav
to access theme. In addition, we require the subnav items parent slug:
Default Usage:
$bp->bp_options_nav[$parent_slug][$slug][$data] = $value;
For example, if you intend to modify the 'Change Avatar' submenu item, under the 'Profile' tab, then you would use the parent slug profile
and the target submenu item's slug, in this case change-avatar
(Default BP submenu items may have their slug as an id, when viewing it in the source):
$bp->bp_options_nav['profile']['change-avatar']['name'] = 'Change Profile Picture';
Here, the final code snippet:
function mb_profile_menu_tabs(){
global $bp;
$bp->bp_nav['activity']['position'] = 15;
$bp->bp_nav['messages']['position'] = 10;
$bp->bp_nav['messages']['name'] = 'Mail';
$bp->bp_nav['friends']['name'] = 'Contacts';
$bp->bp_nav['profile']['name'] = 'Account';
$bp->bp_options_nav['profile']['change-avatar']['name'] = 'Change Profile Picture';
}
add_action('bp_setup_nav', 'mb_profile_menu_tabs', 201);
As usual, please feel free to point out mistakes or improvements.
Said on Sep 16, 2013 by raul -
Said on Sep 17, 2013 by Maximilian -
Said on Aug 28, 2014 by Paul -
Said on Nov 13, 2013 by kmiekio -
Said on Feb 18, 2014 by Maximilian -
Said on Nov 18, 2013 by Kian -
Said on Feb 11, 2014 by Cory I -
Said on Mar 14, 2014 by matthew -
Said on Mar 22, 2014 by Kris -
Said on May 22, 2014 by Austin -
Said on Jun 17, 2014 by Peter Netz Lassen -
Said on Oct 6, 2014 by Roman -
Said on Aug 2, 2015 by Michael Eisenwasser -
Said on Oct 19, 2016 by chetan -
Said on Jul 7, 2019 by JCfromKC -