Last active
September 18, 2023 10:03
-
-
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.  { | |
/** | |
* 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' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Block functions | |
require_once( get_stylesheet_directory() . '/blocks/block-functions.php' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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