How do I use the buddypress username in a shortcode?

I’m trying to link to Buddypress groups, and I need the username of the logged in user to do this. Here is my current shortcode, which is fine, but just outputs // in the URL with no username between.

// Add Shortcode
function my_groups_button() {
ob_start(); ?>
<a href="https://acaffiliates.coach/members/<?php echo bp_core_get_username($user_id); ?>/groups/"> My Groups</a>
<?php
    return ob_get_clean();
}
add_shortcode( 'my-groups-button', 'my_groups_button' );

Read more here: How do I use the buddypress username in a shortcode?

Leave a Reply

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