BuddyPress: Add a Custom Tab to Member Profiles
Adds a new tab to every BuddyPress member profile with your own content, for example "Portfolio" showing the member's posts.
Opens WPIDE on
Code
if ( ! function_exists( 'buddypress' ) ) {
return;
}
$wpide_bp_tab_name = 'Articles';
$wpide_bp_tab_slug = 'articles';
add_action( 'bp_setup_nav', function () use ( $wpide_bp_tab_name, $wpide_bp_tab_slug ) {
bp_core_new_nav_item( array(
'name' => $wpide_bp_tab_name,
'slug' => $wpide_bp_tab_slug,
'position' => 70,
'default_subnav_slug' => $wpide_bp_tab_slug,
'show_for_displayed_user' => true,
'screen_function' => function () {
add_action( 'bp_template_content', function () {
$posts = get_posts( array( 'author' => bp_displayed_user_id(), 'numberposts' => 10, 'no_found_rows' => true ) );
if ( ! $posts ) {
echo '<p>No articles yet.</p>';
return;
}
echo '<ul class="wpide-bp-articles">';
foreach ( $posts as $post ) {
printf( '<li><a href="%1$s">%2$s</a> <small>%3$s</small></li>', esc_url( get_permalink( $post ) ), esc_html( get_the_title( $post ) ), esc_html( get_the_date( '', $post ) ) );
}
echo '</ul>';
} );
bp_core_load_template( 'members/single/plugins' );
},
) );
}, 100 );
Notes
The example lists the member's published posts; replace the content callback with your own output.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.