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 badges
Add a comment  | 

2 Answers 2

Reset to default 2

You 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