Support

Account

Forum Replies Created

  • Did You managed that to work properly?
    Cause I’ve got similar problem with my blocks, much simpler code:

    <?php
    
      // Create class attribute allowing for custom "className" and "align" values.
      $class_name = 'my-block';
      if ( ! empty( $block['className'] ) ) {
        $class_name .= ' ' . $block['className'];
      }
    
      if ( ! empty( $block['align'] ) ) {
        $class_name .= ' align' . $block['align'];
      }
    
      if ( ! empty( $block['alignText'] ) ) {
        $class_name .= ' text-align-' . $block['alignText'];
      }
    
      $anchor = '';
      if ( ! empty( $block['anchor'] ) ) {
        $anchor = 'id="' . esc_attr( $block['anchor'] ) . '" ';
      }
    
      $custom_id = wp_unique_id( 'custom-' );
    
      $attrs = $is_preview ? 'class="'.$class_name.'"' : get_block_wrapper_attributes(
        [
          'class' => $class_name
        ]
      );
    
    ?>
    
      <section <?php echo $anchor; ?> <?php echo $attrs; ?>>
    
        <!-- my block content -->
    
      </section><!-- /.full-section -->
    

    In admin panel my SECTION is wrapped with extra div, on frontend everything is fine.
    I’ve got problem with double classes in frontend too, when I remove this code:
    $class_name .= ' ' . $block['className'];
    it’s better, but in admin panel it’s a little pain in ass.

  • I’ve notice that You need to add:

    if ( ! empty( $block['align'] ) ) {
        $class_name .= ' align' . $block['align'];
      }
    
      if ( ! empty( $block['alignText'] ) ) {
        $class_name .= ' text-align-' . $block['alignText'];
      }

    in block PHP file to render this values properly on frontend.

    I’ve spend dozens hours to test everything, it’s not perfect to create block with ACF, but I can managed that to work with them.

Viewing 2 posts - 1 through 2 (of 2 total)