create blocks programmtically on theme activation

You can’t use block templates this way. They are used only by Gutenberg on client side (JavaScript) when new post content is created. In your case you are creating page on server side (PHP). However you can create pages with initial block structure. Create new page manually and save it without adding any content (there will be only empty block structure as defined by your block template). Then get it’s post_content value either from database using some DB client, or read and print it in some temporary PHP function. But you must get value exactly as stored in database. Use this text as string value for post_content in your page creation code.

This way you will have new page created with initial content matching your block template. Don’t forget to change value if you change template structure.

Leave a Comment