Last active
January 18, 2024 16:00
-
-
Save jnicol/cbbc10deee06526a3f6d296ce82c74de to your computer and use it in GitHub Desktop.
Register/unregister WordPress Gutenberg block styles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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" | |
}); | |
} ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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