Gutenberg add a custom metabox to default blocks

Using filters we can modify the props and attributes of blocks. First we extend the attributes to include the new attribute: const { addFilter } = wp.hooks; // Register/add the new attribute. const addExtraAttribute = props => { const attributes = { …props.attributes, extra_attribute: { type: “string”, default: “default_value” } }; return { …props, attributes … Read more

How To Have Two Gutenberg Editors On One Post?

You could add some kind of separator (a separator block?) in Gutenberg, then filter the_content() to check for the separator to display each half, by setting a switch on the first half and detecting it for the second: add_filter(‘the_content’, ‘content_splitter’); function content_splitter($content) { $separator = “<!– wp:core/separator”; $pos = strpos($content, $separator); if ($pos !== false) … Read more

How to use wp.hooks.addAction() in React JS/Gutenberg?

How to use wp.hooks.addAction? It’s basically like so, just like you’ve attempted: // Hook to the hook_name action. wp.hooks.addAction( ‘hook_name’, ‘namespace’, function(){ console.log( ‘Foo Bar’ ); } ); // Trigger the hook_name action. wp.hooks.doAction( ‘hook_name’ ); Or for hooks which provides one or more parameters to the callback: // Hook to the hook_name action. wp.hooks.addAction( … Read more

Help Unregistering a Core Block Type in Gutenberg

Everything works for me with allowed_block_types hook. Example: add_filter( ‘allowed_block_types’, ‘my_function’ ); function my_function( $allowed_block_types ) { return array( ‘core/paragraph’ ); } You can insert the above code to your functions.php file to a custom plugin. It removes all blocks except the Paragraph block. More examples here https://rudrastyh.com/gutenberg/remove-default-blocks.html

Creating conditional blocks for WordPress Gutenberg

In the edit method for your custom block, when rendering the components you can use the “conditional + &&” pattern: <PanelBody title={ __( ‘My Panel’ ) } > { myCustomBool && <MyComponent value={theValue} onChange={ value => { myChangeCallback(value); } } /> } { ‘marmots’ !== myCustomThing && <MyOtherComponent value={theValue} onChange={ value => { myOtherCallback(value); } … Read more

Integrate Gutenberg as a Standalone App

Yes, You can use Gutenberg as a standalone app or CMS agnostic app. Drupal using Gutenberg as a npm module and then integrating in their own CMS. Drupal Gutenberg is decoupling Gutenberg from WordPress and using as JS editor Gutenberg JS. This way, developers can build block for Gutenberg and port it to two different … Read more

show classes as dropdown in guttenberg`s additional css classes input box

You should add a custom plugin. That’s need a PHP main file that include, register a JavaScript file. The source below should result in an plugin. You find a usable solution also in the probs below. PHP part add_action( ‘enqueue_block_editor_assets’, ‘my_gutenberg_scripts’ ); function my_gutenberg_scripts() { wp_register_script( ‘my-editor-enhancement’, plugins_url( ‘editor.js’, __FILE__ ), array( ‘wp-blocks’ ), // … Read more

How to use PanelColorSettings in custom Gutenberg block?

First you need to import the component – const { PanelColorSettings, } = wp.editor; then inside the InspectorControls you call the component <PanelColorSettings title={ __( ‘Color Settings’ ) } colorSettings={ [ { value: color, onChange: ( colorValue ) => setAttributes( { color: colorValue } ), label: __( ‘Background Color’ ), }, { value: textColor, onChange: … Read more

How to detect the usage of Gutenberg

There are several variants: WordPress 4.9, Gutenberg plugin is not active WordPress 4.9, Gutenberg plugin is active WordPress 5.0, Block Editor by default WordPress 5.0, Classic Editor plugin is active WordPress 5.0, Classic Editor plugin is active, but in site console in “Settings > Writing” the option “Use the Block editor by default…” is selected … Read more