How to remove subnav menu item in BuddyPress

To remove a subnav menu item in BuddyPress, you can use the bp_core_remove_subnav_item() function. This function allows you to remove a subnav menu item from a user’s profile page or a group’s profile page.

Here’s an example of how you can use the bp_core_remove_subnav_item() function to remove a subnav menu item from a user’s profile page:

// Remove subnav menu item in BuddyPress
// More snippets at wpunplugged.com 

/**
 * @param int $user_id The ID of the user.
 */
function my_bp_remove_subnav_item( $user_id ) {
    // Check if the current user is the user being viewed
    if ( $user_id == bp_loggedin_user_id() ) {
        // Remove the "My Custom Tab" subnav item
        bp_core_remove_subnav_item( 'activity', 'my-custom-tab' );
    }
}
add_action( 'bp_actions', 'my_bp_remove_subnav_item' );

This code will remove the “My Custom Tab” subnav menu item from the user’s profile page if they are the currently logged in user. You can modify this code to remove a different subnav menu item, or to remove the subnav menu item from a group’s profile page instead.

To add this code to your site, you can add it to your theme’s functions.php file.

Note that this code assumes that you have the BuddyPress plugin installed and activated on your WordPress site. If you don’t have BuddyPress installed, you will need to install and activate it before you can use the bp_core_remove_subnav_item() function.

Share this post

You might also like...

WooCommerce for WordPress Review
Ecommerce

WooCommerce for WordPress Review

WooCommerce for WordPress is a great choice for anyone looking to create an online store. Its user-friendly interface makes setup and customization simple, while its

Read More »
MemberPress Membership login for WordPress Review
Content restriction

MemberPress for WordPress Review

MemberPress for WordPress is a powerful membership plugin that makes it easy to create and manage memberships on any WordPress website. It allows you to

Read More »

Comment

Your email address will not be published. Required fields are marked *