1

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?

1

You can use the Gutenberg Block Template it is used to have a content placeholder for your Gutenberg content.

https://developer.wordpress.org/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' );
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.