New
PeoplePress is here. Community building for WordPress, reimagined. Fast, modern, and built for the communities you've always wanted to run.
See it live

BuddyDev

Search

Display BP User ID by Shortcode

  • Participant
    Level: Initiated
    Posts: 2
    Dale on #42001

    Hi, does anyone know how to display a user ID in the frontend (possibly via a shortcode) So that a BP member can access their user ID? Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #42072

    Hello Dale,

    Thank you for posting here. Please download the following plugin:

    https://github.com/buddydev/bp-shortcodes/archive/refs/heads/master.zip

    and use the following shortcode

    
    // For Logged in user id.
    [bpsc-user-id context=logged]
    
    // For Displayed user id.
    [bpsc-user-id context=displayed]
    
    

    Please let me know if works or not.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 2
    Dale on #42157

    Thanks for your reply,
    before your reply I used this code:

    function razman_user_id_display() {
    if ( bp_is_user() ) {
    $user_id = bp_displayed_user_id();
    } else {
    $user_id = bp_get_member_user_id();
    }

    echo ‘<div class=”myuser-id”>User ID: ‘. $user_id .'</div>’;

    }
    add_action( ‘bp_before_member_header_meta’, ‘razman_user_id_display’ );
    add_action( ‘bp_directory_members_item’, ‘razman_user_id_display’ );

    and worked with a shortcode
    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #42159

    Hello Dale,

    Code seems good to me. You can use this.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved