I would like to load some code before the template begins printing in BuddyPress. What filter or action hook should I use?

I tried a number of them (such as bp_head, bp_include, bp_init), but none of them seem to work. My code is simply never loaded.

The list of filters and action hooks is hundreds of entries long, which is a bit overwhelming to me, since I am fairly new to BuddyPress. So any help would be greatly appreciated.

I am trying to tell BuddyPress to use a different template if certain conditions are met. So I have some code in bp-custom.php and I would need the appropriate filter or action hook to get it working. Preferably one that accepts a $template variable as an argument.

EDIT: I've tried with different action priority numbers (or without) and nothing seems to work. Still need help with this!

closed as off-topic by kaiser Aug 4 '14 at 14:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.


Untested, but I'd start with something like this:

add_action( 'wp', 'your_function', 3 );
function your_function(){
    if ( is_page_template( 'some-template.php' ) ) { 
        if( some condition ) 
            locate_template( array( 'some-other-template.php' ), true );
  • The wp action trigger doesn't work either :( – Paul T. Aug 23 '12 at 2:33
  • 1
    Try changing or removing the action priority number. – shanebp Aug 23 '12 at 13:16
  • Nope, this doesn't work either :( – Paul T. Aug 24 '12 at 1:47
  • Tried it in the functions.php page instead of bp-custom.php and it works like a charm! Thanks! :) – Paul T. Sep 3 '12 at 17:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.