Site logo

Archived topic

Using hooks with BP content, and finding the functions to put in the hook

11 replies · Started by Carsten on March 14, 2020

Viewing posts 1–12 of 12

Hi there, is it possible to move around BuddyPress content using hooks?

1. I want to display my div#item-meta to the the content with the generate_inside_container or generate_after_main_content hooks

2. I want to add a back button from a plugin to my content area using the generate_inside_navigation hook element

I can see that it requires some php skills, after reading all documentation, I need some help to find the functions I should put in?

Thanks

Hi there

2. I managed to add the back button with shortcode, it can be added with shortcode [alg_back_button] or alg_back_button() function.

I would prefer using the function solution for css control, how should the php script look like for adding this function, alg_back_button()?

Hi there,

1. You would need to find the action they're using to add the meta. Then you could remove it:

remove_action( 'their_hook_name', 'their_function_name' );

Then you could add it to your own area:

add_action( 'generate_inside_container', 'their_function_name' );

2. Would this do it?:

add_action( 'generate_inside_navigation', function() {
    echo '<div class="your-class">';
        echo do_shortcode( '[alg_back_button]' );
    echo '</div>';
} );

1. I removed this button from the header, but I'm not able subsequently to add the button after content.
Just to clarify, now that the hook generate_after_content, is defined, will this code still go into an element, or should it be added directly to my functions.php in my child theme? I have tested both, but with same result, nothing is displayed.

Remove:

// Messages button.
			if ( bp_is_active( 'messages' ) )
				remove_action( 'bp_member_header_actions',    'bp_send_private_message_button', 20 );

Add after content:

add_action( 'generate_after_content', 'bp_member_header_actions', 'bp_send_private_message_button', 20 );

Thanks

Try this in your functions.php:

remove_action( 'bp_member_header_actions', 'bp_send_private_message_button', 20 );
add_action( 'generate_after_content', 'bp_send_private_message_button', 20 );

Perfect, it's working, except for the remove_action part, but I can hide it in the header with css.

Just to understand this right, why would this code not work, if I put this code in a hook element instead?

Regards
Carsten

So this is a simple Action Hook function:

add_action( 'the_hook_name', 'the_function_name', the_priority# );

The Hook Element is actually 'building' this code for you.
So you simply need to provide it with the 'function' in the Text Area which could be examples

1. the function name - in your example that could be:

<?php bp_send_private_message_button(); ?>

OR

2. The Function / Code / HTML itself eg.:

<div class="your-class">
    <?php echo do_shortcode( '[alg_back_button]' ); ?>
</div>

Then you're selecting the Hook this code should be executed in and at which priority ie. the order in which this function will be executed, when there are multiple functions being called by the same hook.

1. thanks for the explanation.

2. 2. The Function / Code / HTML itself eg.:

<div class="your-class">
    <?php echo do_shortcode( '[alg_back_button]' ); ?>
</div>

So this is made for having a class for CSS?

Back button widget is a lightweight plugin that lets you add “Back” button to your WordPress site.

Button can be added via widget, [alg_back_button] shortcode or alg_back_button() function.

There is a function for the back button, isn't it better to use that?

Slightly more efficient to use the function over the shortcode - so you could do this instead:

<div class="your-class">
    <?php alg_back_button(); ?>
</div>

The your-class - which you can change to something more relevant can be used to target the <div> container and by proxy the 'button' within.

Thanks for your quick response

Hmmm, did I miss something here, can't I add the div container directly to the element?

Yes, the code i provided here will work.

This archived topic is closed to new replies.