Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Register/unregister WordPress Gutenberg block styles
/**
* Scripts to run when in WordPress Gutenberg editor
*
* Unregister any block styles we don't want user to be able to select
* or register our own custom block styles.
*/
wp.domReady( () => {
// Unregister any block styles we don't want user to be able to select
wp.blocks.unregisterBlockStyle( 'core/quote', 'default' );
wp.blocks.unregisterBlockStyle( 'core/quote', 'large' );
wp.blocks.unregisterBlockStyle( 'core/button', 'default' );
wp.blocks.unregisterBlockStyle( 'core/button', 'outline' );
wp.blocks.unregisterBlockStyle( 'core/button', 'squared' );
// Add custom block styles:
wp.blocks.registerBlockStyle("core/button", {
name: "mycustomstyle",
label: "My Custom Style"
});
} );
<?php
function enqueue_block_editor_scripts() {
wp_enqueue_script(
'theme-block-editor-js',
get_stylesheet_directory_uri() . '/js/blocks/block-editor-scripts.js',
array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' ), // specify dependencies to avoid race condition
'1.0',
true
);
}
add_action('enqueue_block_editor_assets', 'enqueue_block_editor_scripts');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment