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.
1 2 3 4 5 6 7 8 9 10 11 | 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 its display functions. The example below will override the activity template part.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 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' ; } |