@eluyawi
You can use the following code snippet to create a new tab to display at BuddyPress Profile.
// Function to add a custom tab for Membership Details in the BuddyPress profile
function wbcom_rcp_buddypress_add_membership_tab() {
global $bp;
// Define a new navigation item for the BuddyPress profile menu
bp_core_new_nav_item(array(
'name' => __('Membership', 'textdomain'), // The name of the tab
'slug' => 'membership', // The slug for the tab, used in the URL
'screen_function' => 'wbcom_rcp_buddypress_membership_screen', // The function that will load when the tab is clicked
'position' => 50, // Position of the tab in the profile navigation
'parent_url' => bp_loggedin_user_domain() . '/membership/', // The parent URL for this sub-navigation
'parent_slug' => $bp->profile->slug, // The slug of the parent navigation item
'default_subnav_slug' => 'membership' // Default sub-navigation slug
));
}
// Function to handle the display of the Membership Details tab content
function wbcom_rcp_buddypress_membership_screen() {
// Add the title and content to the Membership tab using actions
add_action('bp_template_title', 'wbcom_rcp_buddypress_membership_screen_title');
add_action('bp_template_content', 'wbcom_rcp_buddypress_membership_screen_content');
// Load the BuddyPress plugin template for displaying the tab content
bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
}
// Function to set the title of the Membership Details tab
function wbcom_rcp_buddypress_membership_screen_title() {
echo 'Membership Details'; // Title displayed on the Membership tab
}
// Function to display the content of the Membership Details tab
function wbcom_rcp_buddypress_membership_screen_content() {
// Use the shortcode [subscription_details] to display membership information
echo do_shortcode('[subscription_details]');
}
// Hook the function to add the Membership tab into the BuddyPress setup navigation action
add_action('bp_setup_nav', 'wbcom_rcp_buddypress_add_membership_tab');
You can use a plugin to add code snippets to your WordPress website using a plugin like “Code Snippets.” This plugin allows you to add custom PHP code snippets to your site without editing your theme’s functions.php file.
Thanks Varun!, I needed this.
Hi Varun, I have checked a problem with your code.
The BuddyPress menu is composed of two parts, a sub menu and the content of the sub menu (I attach a screenshot to explain it).
https://postimg.cc/Hcq07cxK
In this function, I am written in the content part
// Function to set the title of the Membership Details tab
function wbcom_rcp_buddypress_membership_screen_title() {
echo 'Membership Details'; // Title displayed on the Membership tab
}
How can I create a submenu in the SubMenu part of BuddyPress? (In the screenshot it’s vere clear
I have found the solution.
Thanks!