Are you looking for a way to add a new tab or custom navigation in BuddyPress? While there’s probably a plugin for this, we have created a quick code snippet that you can use to add custom navigation in BuddyPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
add_action( 'bp_setup_nav', 'wps_sample_action', 50 );
function wps_sample_action() {
global $bp;
bp_core_new_nav_item(
array(
'name' => __( 'Sample Page', 'buddypress' ),
'slug' => 'sample',
'position' => 50,
'screen_function' => 'wps_sample_action_template',
'default_subnav_slug' => 'sample',
'parent_url' => $bp->loggedin_user->domain . $bp->slug . '/',
'parent_slug' => $bp->slug
) );
}
function wps_sample_action_template() {
add_action( 'bp_template_title', 'wps_sample_action_title' );
add_action( 'bp_template_content', 'wps_sample_action_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function wps_sample_action_title() {
echo 'Sample page title';
}
function wps_sample_action_content() {
echo 'Sample page content';
}
You can load whatever content you place within wps_sample_action_content() function. You could potentially have anything within this function including a custom loop to show members, activity or really anything you can think of. It enables you to adjust the slug, the text displayed within the tab, tab position, and so on.
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 9 best WordPress events plugins and 9 best WordPress accordion plugins.
Comments Leave a Reply