Skip to content

Instantly share code, notes, and snippets.

@zgordon
Created April 13, 2018 18:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zgordon/93377d7ee61fbdbb50bd817c61ffc62b to your computer and use it in GitHub Desktop.
Save zgordon/93377d7ee61fbdbb50bd817c61ffc62b to your computer and use it in GitHub Desktop.
Example of how to set default blocks for a post in Gutenberg with block templates.
<?php
function wpvipblocks_templates( $args, $post_type ) {
if ( $post_type == 'post' ) {
$args['template_lock'] = true;
$args['template'] = [
[
'core/heading', [
'placeholder' => 'Add heading here.',
]
],
[
'core/image', [
'align' => 'right',
]
],
[
'core/paragraph', [
'align' => 'left',
'placeholder' => 'Add your description here.',
]
]
];
}
return $args;
}
add_filter( 'register_post_type_args', 'wpvipblocks_templates', 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment