Last active
February 15, 2018 13:45
-
-
Save zgordon/b9e31a7d8a0e1dc0d356b92360512096 to your computer and use it in GitHub Desktop.
This shows how to create a custom post type and assign it a block template. This would likely go in your functions.php file.
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 mytheme_create_post_type() { | |
register_post_type( 'mytheme_event', | |
[ | |
'labels' => [ | |
'name' => __( 'Events' ), | |
'singular_name' => __( 'Event' ) | |
], | |
'public' => true, | |
'show_in_rest' => true, | |
// Optionally lock templates from further changes | |
// Change to 'insert' to allow adding other blocks, but lock defined blocks | |
'template_lock'] = 'all'; | |
// Set block template | |
'template' => [ | |
[ | |
// Example of including a core image block | |
// Optional alignment setting | |
'core/image', [ | |
'align' => 'left', | |
] | |
], | |
[ | |
// Example of including a core paragraph block | |
// Optional alignment placeholder setting | |
'core/paragraph', [ | |
'placeholder' => 'The only thing you can add', | |
'align' => 'right', | |
] | |
], | |
[ | |
// Example of including a custom block | |
// Optional placeholder setting | |
'custom/your-blocks', [ | |
'placeholder' => 'Custom placeholder', | |
] | |
] | |
] | |
] | |
); | |
} | |
add_action( 'init', 'mytheme_create_post_type' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment