Gutenberg

The WP Blueprint Classic Theme provides an extension of the Gutenberg Handler to facilitate the registration of custom Gutenberg blocks. With this extension, you can easily add your own custom blocks to the block editor for creating dynamic content. This guide will walk you through the process of utilizing the Gutenberg Handler Extension.

Using the Gutenberg Handler Extension

Create an Extended Class: To utilize the Gutenberg Handler Extension, you need to create a new class that extends the base Gutenberg Handler class provided by WP Blueprint Classic Theme.

namespace WPBlueprint\Theme\Classic\Utilities;

class Gutenberg extends \WPBlueprint\Theme\Core\Handlers\Gutenberg {
    // ...
}

Define Custom Blocks: Within your extended Gutenberg class, you can define an array of custom blocks you want to register. Each block is represented as an associative array within the $blocks array.

class Gutenberg extends \WPBlueprint\Theme\Core\Handlers\Gutenberg {
    public function __construct() {
        $blocks = [
            // Define your custom Gutenberg blocks here.
        ];

        parent::set_blocks( $blocks );
    }
}

Register Custom Blocks: The blocks defined in the $blocks array will be registered automatically when you create an instance of your extended Gutenberg class.

Adding Custom Blocks

Define Blocks: Inside the constructor of your extended Gutenberg class, add the custom blocks you want to register. Each block is represented by an array containing its name and arguments.

class Gutenberg extends \WPBlueprint\Theme\Core\Handlers\Gutenberg {
    public function __construct() {
        $blocks = [
            [
                'name' => 'custom-block',
                'args' => [
                    'title' => 'Custom Block',
                    'icon'  => 'your-icon',
                    // Add more block arguments...
                ],
            ],
            // Add more custom blocks...
        ];

        parent::set_blocks( $blocks );
    }
}

Customizing Block Attributes

You can customize each block’s attributes by providing arguments in the args array when defining your custom blocks.


First PublishedAugust 14, 2023
Last UpdatedAugust 18, 2023