Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_get_template_part()

Use bp_get_template_part() when you want to filter a BuddyPress template part. You will need to pass your function three arguments ( $templates, $slug, $name ). The example below will swap out the activity.php template part when that template part is called. If you do not supply a $slug, it will swap out every template part bp_get_template_part is calling on that  page.


function my_template_part_filter( $templates, $slug, $name ) {

    if ( 'members/single/activity' != $slug )
	return $templates;

    return bp_get_template_part( 'members/single/plugins' );
}

add_filter( 'bp_get_template_part', 'my_template_part_filter', 10, 3 );

Note: For an actual example of overloading an existing template part from a plugin, see Template Overload from a Plugin

If you want to programmatically supply the content without using a template file ¬†load plugins.php and utilize it’s display functions. The example below will override the activity template part.

function my_template_filter_init() {

add_action( 'bp_template_title', 'my_filter_template_title' );
add_action( 'bp_template_content', 'my_filter_template_content' );
add_filter( 'bp_get_template_part', 'my_template_part_filter', 10, 3 );

}
add_action('bp_init', 'my_template_filter_init');

function my_template_part_filter( $templates, $slug, $name ) {

if ( 'members/single/activity' != $slug )
	return $templates;

    return bp_get_template_part( 'members/single/plugins' );
}

function my_filter_template_title() {
    echo 'Title';
}

function my_filter_template_content() {
    echo 'Content';
}