Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Generateblocks 1.7 container hook usage

  • 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 hook

    Is 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

  • 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

  • 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

  • You’re welcome!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.