WordPress Gutenberg, update post content programmatically WordPress Gutenberg, update post content programmatically wordpress wordpress

WordPress Gutenberg, update post content programmatically


ACF has an ability to pre-init fields before post will be visible to user on post creation page. You can try to use this function to set desired content to fields.

You can read about this here:https://www.advancedcustomfields.com/resources/acf-prepare_field/


As of Wordpress 5.0.0

You can use template and template_lock arguments upon registering your custom post type.

You can then set an array of specific blocks to use and you can chose to restrict users from adding new blocks or removing them.

AttributeDescription
template(array) Array of blocks to use as the default initial state for an editor session. Each item should be an array containing block name and optional attributes.
template_lock(string/false) Whether the block template should be locked if $template is set. If set to 'all', the user is unable to insert new blocks, move existing blocks and delete blocks. If set to 'insert', the user is able to move existing blocks but is unable to insert new blocks and delete blocks. Default false.

A short example would be something along the lines of...

<?php$args = [    //...    'template_lock' => 'all',    'template' => [        [ 'core/paragraph' ],        [ 'core/file' ],        //...    ],    //...];register_post_type( $post_type, $args );?>

Currently, Gutenberg documentation is scarced, you can find a complete list of blocks & parameters @ https://github.com/WordPress/gutenberg/tree/master/packages/block-library/src


Gutenberg is still in development, some features don't act as they should.