Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_get_template_part Filter

Use the bp_get_template_part filter when you want to filter the template returned by BuddyPress’s bp_get_template_part() function. Your filter should accept three arguments ( $templates, $slug, $name ).

The example below illustrates how you can use the bp_get_template_part filter to change the template that’s used to display the activity tab of a member’s profile.


function my_template_part_filter( $templates, $slug, $name ) {
    
    // check whether the current template being fetched is the activity template.  If not, just return the current template
    if ( 'members/single/activity' != $slug )
	return $templates;

    // current template being fetched is the activity template.  Replace it with the generic plugins.php template
    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';
}

Skip to toolbar