- This topic has 11 replies, 3 voices, and was last updated 4 years, 1 month ago by David.
-
AuthorPosts
-
March 14, 2020 at 7:42 am #1194762Carsten
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
March 14, 2020 at 2:40 pm #1194995CarstenHi 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()?
March 14, 2020 at 3:53 pm #1195030TomLead DeveloperLead DeveloperHi 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>'; } );
March 15, 2020 at 3:49 am #1195268Carsten1. 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
March 15, 2020 at 5:41 am #1195343DavidStaffCustomer SupportTry 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 );
March 15, 2020 at 8:12 am #1195588CarstenPerfect, 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
CarstenMarch 15, 2020 at 8:47 am #1195603DavidStaffCustomer SupportSo 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 examples1. 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.
March 15, 2020 at 12:44 pm #1195747Carsten1. 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?
March 15, 2020 at 12:51 pm #1195752DavidStaffCustomer SupportSlightly 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.March 15, 2020 at 12:54 pm #1195757CarstenThanks for your quick response
March 15, 2020 at 1:09 pm #1195764CarstenHmmm, did I miss something here, can’t I add the div container directly to the element?
March 15, 2020 at 4:02 pm #1195846DavidStaffCustomer SupportYes, the code i provided here will work.
-
AuthorPosts
- You must be logged in to reply to this topic.