Search code examples
phpwordpresshookgutenberg-blocks

Create a page with gutenberg HTML block automatically upon plugin activation


I have managed to create a page upon plugin activation. i need to add content to the page that get created. so i used following code. The problem is it creates a classic editor in the page and not the gutenberg HTML editor.

register_activation_hook( __FILE__, 'my_plugin_install_function');

function my_plugin_install_function()
  {
   //post status and options
    $post = array(
          'comment_status' => 'closed',
          'ping_status' =>  'closed' ,
          'post_author' => get_current_user_id(),
          'post_date' => date('Y-m-d H:i:s'),
          'post_name' => 'Checklists',
          'post_status' => 'publish' ,
          'post_content'   => '[customization-shortcode]',
          'post_title' => 'Checklists',
          'post_type' => 'dash',
    );  
    //insert page and save the id
    $newvalue = wp_insert_post( $post, false );
    //save the id in the database
    update_option( 'hclpage', $newvalue );
  }

i expect to have my shortcode displayed in a gutenberg HTML block and not the classic editor


Solution

  • I have found a solution to this, all i did is change following line:

    'post_content'   => '[customization-shortcode]',
    

    to

    'post_content'   => '<!-- wp:html -->[customization-shortcode]<!-- /wp:html -->',
    

    This will create a usual gutenberg HTML block instead the old classic one.