Skip to content

Instantly share code, notes, and snippets.

@ptesei
Created May 17, 2022 07:07
Show Gist options
  • Save ptesei/2d7897eff59513c1099f571d8d27576c to your computer and use it in GitHub Desktop.
Save ptesei/2d7897eff59513c1099f571d8d27576c to your computer and use it in GitHub Desktop.
example innerblocks patterns
add_action('acf/init', 'my_acf_init_blocks');
function my_acf_init_blocks() {
// Check function exists.
if( function_exists('acf_register_block_type') ) {
// Register a restricted block.
acf_register_block_type(array(
'name' => 'restricted',
'title' => 'Restricted',
'description' => 'A restricted content block.',
'category' => 'formatting',
'mode' => 'preview',
'supports' => array(
'align' => true,
'mode' => false,
'jsx' => true
),
'render_template' => 'template-parts/blocks/inner-example.php',
));
}
if( function_exists('acf_register_block_type') ) {
// Register a restricted block.
acf_register_block_type(array(
'name' => 'restricted-template',
'title' => 'Restricted Template',
'description' => 'A restricted content block.',
'category' => 'formatting',
'mode' => 'preview',
'supports' => array(
'align' => true,
'mode' => false,
'jsx' => true
),
'render_template' => 'template-parts/blocks/inner-example-template.php',
));
}
}
register_block_pattern(
'my-plugin/example-pattern',
array(
'title' => __( 'Example pattern', 'my-plugin' ),
'keyword' => array( 'example','test' ),
'content' => '<!-- wp:paragraph {"backgroundColor":"black","textColor":"white"} -->
<p class="has-white-color has-black-background-color has-text-color has-background">Powered by WordPress</p>
<!-- /wp:paragraph -->',
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment