Skip to content

Instantly share code, notes, and snippets.

@johnmccole
Last active September 18, 2023 10:03
Show Gist options
  • Save johnmccole/1f94a6f147e86a199d297de87ae1103d to your computer and use it in GitHub Desktop.
Save johnmccole/1f94a6f147e86a199d297de87ae1103d to your computer and use it in GitHub Desktop.
Add custom ACF Pro custom Gutenberg blocks to a Bootscore child theme. NOTE: block.json MUST be called block.json, any other name will not work. Wildcards do not work for block directories either, must be named. ![](https://cdn.cacher.io/attachmen
<?php
/**
* We use WordPress's init hook to make sure
* our blocks are registered early in the loading
* process.
*
* @link https://developer.wordpress.org/reference/hooks/init/
*/
function register_acf_blocks() {
/**
* We register our block's with WordPress's handy
* register_block_type();
*
* @link https://developer.wordpress.org/reference/functions/register_block_type/
*/
// Duplicate this line for every custom block required.
register_block_type( __DIR__ . '/testimonial/block.json' );
}
// Here we call our register_acf_block() function on init.
add_action( 'init', 'register_acf_blocks' );
{
"name": "acf/testimonial",
"title": "Testimonial",
"description": "A custom testimonial block that uses ACF fields.",
"category": "formatting",
"icon": "admin-comments",
"keywords": ["testimonial", "quote"],
"acf": {
"mode": "auto",
"renderTemplate": "testimonial.php"
},
"supports": {
"anchor": true
}
}
// Block functions
require_once( get_stylesheet_directory() . '/blocks/block-functions.php' );
<?php
/**
* Testimonial Block template.
*
* @param array $block The block settings and attributes.
*/
$title = get_field('title');
?>
<div id="<?= $block['id'] ?>" class="testimonial-block custom-block">
<p class="title"><?= $title ?></p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment