Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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 );
share|improve this answer
The wp action trigger doesn't work either :( –  Paul T. Aug 23 '12 at 2:33
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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