I’m trying to place an “Add Friend” button outside of the members page, inside a loop, so the button appears next to the author’s avatar in a post.
I tried adding ;
<?php if ( bp_is_active( 'friends' ) ) { ?>
<?php bp_add_friend_button( $user_ids['users'][$i]->id ) ?>
<?php } ?>
Inside the loop but it didn’t return any results.
Then I placed the following action hook in functions.php, it displayed the button inside the loop but once clicked, all the buttons in the post list got clicked as well.
add_action( âthe_contentâ, âbp_add_friend_buttonâ, 5 );
So now I’m stuck. I thought, adding a template tag inside the template would work since it had worked for “Send Message” button.
try
<?php if ( function_exists( 'bp_add_friend_button' ) ) : ?>
<?php bp_add_friend_button() ?>
<?php endif; ?>
Here is an example that works for me, hope its helps.
There may be a plugin that solve this, but to followup on Rafa’s solution.
This complete code worked for me.
In bp-custom.php ( this is a file you need to create)