Support

Account

Home Forums Gutenberg Programatically registering ACF field blocks in Gutenberg Reply To: Programatically registering ACF field blocks in Gutenberg

  • It seems that underscores in block name isn’t passing though.

    So, textarea_block as a block name is not working, instead use a name without underscores, something like textareablock.

    Try this:

    if( function_exists('acf_register_block') ) {
    
      acf_register_block(array(
        'name'				=> 'textareablock',
        'key'				=> 'textarea_block',
        'title'				=> __('textarea'),
        'description'		=> __('A custom pixel block.'),
        'render_callback'	=> 'textarea_block_render_callback',
        'category'			=> 'formatting',
        'mode'              => 'edit', // 'preview',
        'icon'				=> 'admin-comments',
        'keywords'			=> array( 'flexible', 'quote' ),
      ));
    }
    
    register_field_group(array (
      'key' => 'textarea',
      'title' => 'Text Area',
      'fields' => array(
        array(
          'key' => 'textarea_title',
          'name' => 'textarea_title',
          'label' => 'Section Title',
          'instructions' => '',
          'type' => 'text',
        ),
        array(
          'key' => 'textarea_text',
          'name' => 'textarea_text',
          'label' => 'Text',
          'instructions' => '',
          'type' => 'wysiwyg',
        ),
      ),
      'location' => array (
        array (
          array (
            'param' => 'block',
            'operator' => '==',
            'value' => 'acf/textareablock'
          ),
        ),
      ),
    ));

    P.S. I’ve added 'mode'=> 'edit' to start ACF block in edit more.