Support

Account

Home Forums Gutenberg Register Block Parent Attribute Reply To: Register Block Parent Attribute

  • In case anyone else is looking for an answer, I found a solution…

    Use block filters.

    The blocks.registerBlockType filter lets you modify block settings. So, I just added a parent setting with the block I wanted as a parent. Since the parent prop takes an array of blocks, more than one parent can be named.

    
    /**
     * Set ACF block parent
     * @param {obj} settings 
     * @param {string} name 
     */
    function setBlockParent( settings, name ) {
        if ( name !== 'acf/post-content' ) {
            return settings;
        }
     
        return lodash.assign({}, settings, {
            parent: [
    			'namespace/featured-content',
    		]
        } );
    }
     
    addFilter(
        'blocks.registerBlockType',
        'namespace/set-post-content-parent',
        setBlockParent
    );

    Hope it helps anyone else.

    ref: https://developer.wordpress.org/block-editor/developers/filters/block-filters/#filters