WordPress Development Asked by Dragon on January 7, 2021
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?
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' );
Correct answer by Tim on January 7, 2021
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');
});
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 );
Answered by Will on January 7, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP