I am trying to register a custom block using metadata from block.json. I created the block.json
file -
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"title": "Example",
"name": "example/example-01-basic",
"category": "text",
"icon": "universal-access-alt",
"editorScript": "file:./block.js",
"render": "file:./block.php"
}
Saved the file in block
directory. Called the PHP register_block_type
function from functions.php
in the root directory -
function register_block() {
register_block_type(__DIR__ . '/block/block.json');
}
add_action('init', 'register_block');
The block.js JS file being qneueued using
editorScriptis also present in the
block` directory -
import { registerBlockType } from '@wordpress/blocks';
import metadata from './block.json';
registerBlockType(metadata, {
edit: null,
save: null,
});
I have kept the edit and save methods null since the block is rendering using PHP. Everything seems to be ok but the block is not showing up in Block Editor. What am I doing wrong? Any help is highly appreciated. Bashing my head for a whole day now.