首页 > 解决方案 > 插件激活后自动创建一个带有古腾堡 HTML 块的页面

问题描述

我已经设法在插件激活时创建了一个页面。我需要向创建的页面添加内容。所以我使用了以下代码。问题是它在页面中创建了一个经典编辑器,而不是古腾堡 HTML 编辑器。

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 );
  }

我希望我的简码显示在古腾堡 HTML 块中,而不是经典编辑器中

标签: phpwordpresshookgutenberg-blocks

解决方案


我找到了解决方案,我所做的只是更改以下行:

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

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

这将创建一个通常的古腾堡 HTML 块,而不是旧的经典块。


推荐阅读