Skip to content

Instantly share code, notes, and snippets.

@khromov
Created June 9, 2022 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khromov/632ccaee4cf9331c03bbda56ab99df41 to your computer and use it in GitHub Desktop.
Save khromov/632ccaee4cf9331c03bbda56ab99df41 to your computer and use it in GitHub Desktop.
WordPress Gutenberg - Add a locked template to a post type
<?php
add_action('init', function() {
// For which posts type
$post_type_object = get_post_type_object( 'post' );
// Which allowed blocks
$post_type_object->template = [
['core/heading', ['level' => '5', 'content' => 'Default value']],
['core/paragraph'],
['core/image'],
];
// Makes it impossible to move posts
$post_type_object->template_lock = 'all';
});
@alexstrand
Copy link

Thanks! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment