admin管理员组文章数量:1293985
When I open the block editor on a new post or page or edit an existing post or page, the Default Gutenberg Block is the paragraph block. How do I change this to a gallery block or another block?
When I open the block editor on a new post or page or edit an existing post or page, the Default Gutenberg Block is the paragraph block. How do I change this to a gallery block or another block?
Share Improve this question edited Sep 29, 2020 at 19:45 Will 7617 silver badges24 bronze badges asked Sep 25, 2020 at 19:58 DragonDragon 131 silver badge3 bronze badges2 Answers
Reset to default 2You can use the Gutenberg Block Template it is used to have a content placeholder for your Gutenberg content.
https://developer.wordpress/block-editor/developers/block-api/block-templates/
<?php
function myplugin_register_template() {
$post_type_object = get_post_type_object( 'post' );
$post_type_object->template = array(
array( 'core/image' ),
);
}
add_action( 'init', 'myplugin_register_template' );
This is possible with the setDefaultBlockName function although it is poorly documented at the moment.
You can try this out by placing this in the developers console of your web browser while you have the block editor open.
wp.domReady(() => {
wp.blocks.setDefaultBlockName('core/quote');
});
(source)
I would recommend that you create a custom plugin; and start with this (haven't tested, but should work).
function change_default_block {
wp_register_script( 'js-change-default-block', plugin_dir_path( __FILE__ ) . '/js/change-default-block.js', '', '', true );
}
add_action( 'wp_enqueue_scripts', 'change_default_block', 4 );
本文标签: How to change the Default block in the blockeditor away from the paragraph block
版权声明:本文标题:How to change the Default block in the block-editor away from the paragraph block? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741591549a2387158.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论