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.

generateblock remove container condition

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

  • 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

  • Hi @liquidonthedrums,

    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   🙂

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