Created
September 22, 2021 20:25
-
-
Save eclarrrk/608e98b9a3341a8c82d28e855c4c2e0d to your computer and use it in GitHub Desktop.
How to register a block template with an ACF Custom Block and pre-populate it's ACF fields.
This file contains 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 | |
function register_csg_patterns() { | |
} | |
add_action( 'init', 'register_csg_patterns' ); | |
function myBlockTemplate() { | |
$myBlockTemplate = get_post_type_object( 'myCustomPostType' ); // Adds these blocks to a specific post type | |
$myBlockTemplate->template = array( | |
array( 'acf/csg-group', // use 'acf/myBlockSlug' to call you custom block | |
array( "data" => | |
array( | |
// In addition to core block properties, this array can store ACF custom block properties. | |
// Each of the custom fields used here are button group fields, which need a specific value to be antered for it to work. | |
"align" => "wide", // THis is the core block width setting | |
"background_color" => "transparent", // Use ACF field slug and a corresponding value | |
"height" => "medium", | |
"style" => "halftone-bottom-left", | |
), | |
), | |
array( | |
// This ACF block uses InnerBlocks. Child blocks go here. | |
array( 'core/paragraph', | |
array( | |
'content' => 'Add a brief job description here.' | |
) | |
), | |
) | |
), | |
array( 'core/heading', array( | |
'level' => 2, 'content' => 'Duties' ) ), | |
array( 'core/paragraph' ), | |
array( 'core/heading', array( | |
'level' => 2, 'content' => 'Qualifications' ) ), | |
array( 'core/list' ), | |
array( 'core/heading', array( | |
'level' => 2, 'content' => 'Physical Requirements' ) ), | |
array( 'core/list' ), | |
); | |
} | |
add_action( 'init', 'careers_template' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment