Support

Account

Home Forums Gutenberg Moving register_block_type out of functions.php

Unread

Moving register_block_type out of functions.php

  • I’m new to the V2 ACF blocks and I’m trying to keep my blocks within a folder in my theme. I don’t want to have to add code into functions.php, but would rather keep it all in one contained folder.

    Within my theme, I’ve created a ‘blocks’ folder and then a folder within that, let’s call it ‘block’

    In that folder, I have my block.json file and my render template that is referenced within the block.json file.

    When I register the block with this code in my functions.php, it works fine:

    add_action( 'init', 'register_acf_blocks' );
    function register_acf_blocks() {
        register_block_type( __DIR__ . 'path to block folder' );
    }

    But in the docs, it says that I can “… either put this in your plugin’s PHP file, or in your theme’s functions.php file or equivalent.”

    Does this mean I can add it to the top of the render template? Such as:

    add_action( 'init', 'register_acf_blocks' );
    function register_acf_blocks() {
        register_block_type( __DIR__ );
    }

    This doesn’t work, and I’ve also tried creating a separate php file within the block folder that is not the render template, then adding this code. Doesn’t seem to work.

    Thanks!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.