Reputation: 41
I tried to create a Gutenberg block with ACF like described here (https://www.billerickson.net/building-acf-blocks-with-block-json/#create-a-block-json-file)
My block.json:
{
"name" : "quick-links",
"title" : "Quick Links",
"apiVersion" : 2,
"icon" : "admin-users",
"mode" : "auto",
"acf": {
"mode": "preview",
"renderTemplate": "quick-links.php"
},
"align" : "full",
"keywords" : [ "Quick-Links", "Links" ]
}
My plugin to register the block:
<?php
/**
* Plugin Name: Gutenberg Block
* Description: Blocks to display photo/video galleries, quicklinks, downloads, ...
* Version: 1.0
*/
add_action( 'init', 'register_acf_blocks', 5 );
function register_acf_blocks() {
register_block_type( __DIR__ . '/blocks/quick-links/block.json' );
}
the quick-links.php just outputs a string.
But the block isn't visible in the page editor. No PHP or JS Errors. Can anyone see a problem?
Upvotes: 1
Views: 2556
Reputation: 3699
There could be a few potential issues with your ACF block registration. In your block.json, the namespace of your block name is missing, which could cause the block registration to fail.
namespace
with your unique block name:block.json
{
"name": "namespace/quick-links",
...
}
The function name register_acf_blocks()
is potentially not a unique function name. The issue could be your function is overwritting an existing function of the same name. Update your block registration function name to be more unique.
If your block is still not rendering or loading, confirm the path to your block.json is correct. Add some debugging info to your block registration function to find out if the block is being registered:
<?php
function register_acf_blocks_namespace_quick_link() {
$status = register_block_type( __DIR__ . '/blocks/quick-links/' ); // block.json not needed
// If register_block_type cannot register the block, it returns false
if(!$status){
error_log('block.json not found');
}
}
add_action( 'init', 'register_acf_blocks_namespace_quick_link', 5 );
Hopefully one or more of the above steps should help resolve your issue..
Upvotes: 1