-
eastriverstudio
In GB 1.7 I noticed there were some new container hooks added:
Feature: Add generateblocks_before_container_open hook
Feature: Add generateblocks_after_container_close hookIs there any guidance available for how these can be used and would it be possible to use them of specific containers only in some way?
What I’m thinking is I could hook in elements to specific containers with a certain attribute such as a class, but without any examples to go on I’m not sure if these hooks are intended for that sort of usage.
Any insight would be much appreciated.
Thanks
-
David
Hi there,
those are filter hooks , not action hooks so you can’t simply hook content into them using GP Elements.
for what you require, you could create a portable hook that gets rendered in a block or added as a shortcode. But GP Elements can only deal with template tag display rules, it can’t check for other things such as block attributes, so that would need more consideration.
-
eastriverstudio
Hi David
OK thanks for clarifying those are filter hooks. Can you provide any examples of filter usage on containers?
What I’m essentially looking for is an easy way to add in third party scripts to certain containers to make the blocks carousels/sliders using purely GB blocks. If I was to filter the container content and append the script, would the filter hook provide anything to allow only certain containers to be targeted?
Thanks
-
Fernando
Hello there,
Here’s an example usage where you can inject a Headline Before and after a Container:
add_filter( 'generateblocks_before_container_open', function( $output, $attributes, $block ) { if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'test-gb-open' ) !== false ) { return $output . '<h2>test</h2>'; } return $output; }, 10, 3 );
add_filter( 'generateblocks_after_container_close', function( $output, $attributes, $block ) { if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'test-gb-open' ) !== false ) { return $output . '<h2>test end</h2>'; } return $output; }, 10, 3 );
The Container in the code should have a class of
test-gb-open
.For your script, is the a specific place where it needs to be added?
-
eastriverstudio
Hi Fernando
Thanks for sharing the examples. That should be enough for me to go on and looks like it will allow me to do what I need in terms of appending the third party snippets inline.
Thanks
-
Fernando
You’re welcome!
- You must be logged in to reply to this topic.