Block Template for New Posts
Starts every new post with a set of placeholder blocks, such as a summary paragraph, a heading and an image, so writers follow the same structure.
Opens WPIDE on
Code
// Post type that gets the template.
$wpide_template_post_type = 'post';
// Blocks and their attributes.
$wpide_template_blocks = array(
array( 'core/paragraph', array( 'placeholder' => 'Summarize the post in one or two sentences...' ) ),
array( 'core/heading', array( 'level' => 2, 'placeholder' => 'First section heading' ) ),
array( 'core/paragraph', array( 'placeholder' => 'Write the first section...' ) ),
array( 'core/image', array() ),
);
// false, 'insert' or 'all'.
$wpide_template_lock = false;
add_action( 'init', function () use ( $wpide_template_post_type, $wpide_template_blocks, $wpide_template_lock ) {
$object = get_post_type_object( $wpide_template_post_type );
if ( ! $object ) {
return;
}
$object->template = $wpide_template_blocks;
if ( $wpide_template_lock ) {
$object->template_lock = $wpide_template_lock;
}
}, 20 );
Notes
Change the post type, the blocks and the lock. Lock 'insert' stops blocks being added or removed; 'all' also stops moving them.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.