Hi there,
I’ve been looking for a way to hide a menu item from users with the “subscriber” role and came across a code snippet but it’s not working as intended. Could someone please guide me in the right direction? I would like to do it without a plugin as I have too many installed on my site already. Is anyone here familiar with this function?
function bp_remove_nav_item() { $current_user = wp_get_current_user(); $role_name = $current_user->roles[0]; if($role_name==='administrator'){ bp_core_remove_nav_item( 'buddyblog' ); } } add_action( 'wp', 'bp_remove_nav_item' );
Hello Chanel,
Thank you for posting. I am assuming you are not using the BuddyBlog Pro plugin. Please try the following code:
add_action( 'bp_buddyblog_setup_nav', function () { $user_id = bp_displayed_user_id(); $user = $user_id ? get_user_by( 'id', $user_id ) : null; if ( $user && array_intersect( (array) $user->roles, array( 'administrator' ) ) ) { bp_core_remove_nav_item( 'buddyblog', 'members' ); } }, 15 );
It will remove the user nav menu
Regards
RaviHi Ravi,
I’m using buddyboss and don’t have buddyblog pro installed. Sadley, the code snippet you provided did not help me achieve my desired result as the menu item is still showing up in the header navigation where I would like to place it. Do you have any other suggestions?
Best regards,
Chanel
You must be logged in to reply to this topic.