简体   繁体   English

在插件激活时自动创建一个带有gutenberg HTML块的页面

[英]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. 问题是它在页面中创建了一个经典编辑器而不是gutenberg 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('Ymd 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 我希望我的短代码显示在gutenberg HTML块中,而不是经典编辑器

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. 这将创建一个通常的gutenberg HTML块而不是旧的经典的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM