Support

Account

Home Forums Gutenberg Registering an array of Gutenberg blocks Reply To: Registering an array of Gutenberg blocks

  • You should be able to call acf_register_block() (which has been renamed to acf_register_block_type() in 5.8.0 release) multiple times in a row without any issues.
    I think the issue might be that the $blocks variable does not contain the blocks data.

    try to do the end of the blocks file like so:

    
    // blocks.php
    ..
    
    $blocks = [
      $headline,
      $paragraph
    ];
    return $blocks;
    

    You can then get the value like so:

    
    // index.php
    function block_acf_init()
    {
        $blocks = require(__DIR__.'/blocks.php');
        
        foreach($blocks as $block) {
            acf_register_block($block);
        }
    }