-
brtekim79
Hi. MR.GP
I can’t find the “generateblock remove container condition” feature in GenerateBlocks 2.0.
I searched about it, and it seems it has been removed. Is this true?I really need the functionality to conditionally remove or hide a container based on certain conditions. Specifically, I need to control container visibility based on whether an ACF field has a value or not.
-
Alvind
Hi there,
That option no longer exists—it was part of GP Premium but hasn’t been included since GB 2.0. We’re working on it.
In the meantime, we can use a custom snippet to achieve the desired condition. Let us know if you need assistance with that.
-
liquidonthedrums
Hi Alvind,
I would be interested in seeing how you implement this functionality with GB 2.0 (via custom snippet)
Thanks
-
Alvind
If you have specific conditions for hiding the block (e.g., when a custom field is empty or returns a particular value), let me know so I can draft a tailored snippet for your requirement. 🙂
-
liquidonthedrums
My use case is to hide a container if an acf checkbox is ticked (ie. value=1).
-
1. Add a CSS class to the container, eg.
custom-condition-container
.
Adding CSS class(es): https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/2. Add this PHP code, and change
checkbox_field_name
to the actual one:add_filter( 'render_block', function( $block_content, $block ) { if ( ! is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'custom-condition-container' ) !== false ) { $checkbox = get_field('checkbox_field_name'); // If checkbox is true, return empty string (hide block) if ($checkbox) { return ''; } // If checkbox is false, return original content return $block_content; } // Return original content if conditions aren't met return $block_content; }, 10, 2 );
-
liquidonthedrums
Hi Ying,
Thanks for the response. Looks great!
-
You are welcome 🙂
- You must be logged in to reply to this topic.