Hi there,
I’m trying to figure out a way to register multiple blocks at a time.
Here’s how I’m trying to do it:
add_action( 'acf/init', 'register_call_to_action_block_2' );
function register_call_to_action_block_2() {
if ( function_exists( 'acf_register_block_type' ) ) {
// Register Call to Action block.
acf_register_block_type(
array(
'name' => 'call-to-action',
'title' => __( 'Call to Actions' ),
'description' => __( 'A custom Call to Action block.' ),
'category' => 'formatting',
'icon' => 'layout',
'keywords' => array( 'call', 'to', 'action' ),
'post_types' => array( 'post', 'page' ),
'mode' => 'preview',
'render_template' => plugin_dir_path( __FILE__ ) . '../views/block-call-to-action.php',
'enqueue_style' => plugin_dir_url( __FILE__ ) . '../assets/css/bplogix-blocks.css',
),
array(
'name' => 'call-out',
'title' => __( 'Call Out' ),
'description' => __( 'A custom Call Out block.' ),
'category' => 'formatting',
'icon' => 'layout',
'keywords' => array( 'call', 'out' ),
'post_types' => array( 'post', 'page' ),
'mode' => 'auto',
'render_template' => plugin_dir_path( __FILE__ ) . '../views/block-call-out.php',
// 'render_callback' => 'call_out_block_render_callback',
// 'enqueue_style' => get_template_directory_uri() . '/template-parts/blocks/call-out/call-out.css',
// 'enqueue_script' => get_template_directory_uri() . '/template-parts/blocks/call-out/call-out.js',
// 'enqueue_assets' => 'call_out_block_enqueue_assets',
)
);
}
}
And then the callback
function my_acf_block_render_callback( $block ) {
// convert name ("acf/testimonial") into path friendly slug ("testimonial")
$slug = str_replace( 'acf/', '', $block['name'] );
// include a template part from within the "template-parts/block" folder.
if ( file_exists( plugin_dir_path( __FILE__ ) . "/views/block-{$slug}.php" ) ) {
include plugin_dir_path( __FILE__ ) . "/views/block-{$slug}.php";
}
}
I tried doing a foreach loop instead but that didn’t seem to work either. Clearly I’m doing something wrong. I saw another topic here on this but that didn’t answer my question unfortunately.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.