E. Jacques
E. Jacques

Reputation: 31

Custom Gutenberg block doesn't appear

I just followed this tutoriel to build a plugin that add a custom block to Gutenberg: https://developer.wordpress.org/block-editor/getting-started/tutorial/

And it's work well. But when i duplicate the PHP and json code to another plugin, the block doesn't appear in Gutenberg. Here is the code:

    <?php
/**
 * Plugin Name:       Custom Block 2
 * Description:       Example block
 * Version:           1.0
 * Author:            Manu225
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       custom-block-2
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}

function create_block_custom_2_block_block_init() {
    register_block_type( __DIR__.'/block');
}
add_action( 'init', 'create_block_custom_2_block_block_init' );

And the block.json:

{
      "$schema": "https://schemas.wp.org/trunk/block.json",
      "name": "create-block/custom-block-2",
      "version": "1.0",
      "title": "Custom Block 2",
      "category": "widgets",
      "icon": "hammer",
      "description": "Example of custom block.",
      "render": "file./render.php",
      "text-domain": "custom-block-2"
    }

The render.php file exist and just have some text without PHP. I don't have any error in the console. I tried to add the block by the JS function registerBlockType, but it's not working too. I don't understand what is missing in my plugin to work like the first one generated with npx command line?

Thanks for help!

Upvotes: 0

Views: 49

Answers (0)

Related Questions