Show date post published in Gutenberg component

I was able to get there by doing the following. import * as wpDate from “@wordpress/date”; You can find the very limited documentation on that here: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-date/ I was able to use the following: const post = wp.data.select(“core/editor”).getCurrentPost(); const postDate = wpDate.format(“d|m|Y”, post.date); Then, when I needed it: <div> <RichText className=”snug huge” placeholder=”Your title here” … Read more

Determine if block has already been registered

EDIT I just realized you’re doing this on the PHP side. There is a class called WP_Block_Type_Registry that you can use to see what is already registered: $registry = WP_Block_Type_Registry::get_instance(); if ( ! $registry->get_registered( ‘foo/column’ ) ) { // YOUR CODE } Gutenberg should fire a console error if a block has already been registered. … Read more

How to get color name in PanelColorSettings in custom Gutenberg block?

I could solve it with the function getColorObjectByColorValue (take a look at the gutenberg files). If you have something like const backgroundColors = [ { name: ‘Light Green’, slug: ‘light-green’, color: ‘#E6F0F0’ }, { name: ‘Light Gray’, slug: ‘light-gray’, color: ‘#F7F7F7’ } ]; then you can get the color name by const test = getColorObjectByColorValue(backgroundColors, … Read more

How to make a custom taxonomy selectable in post publish area?

The reason it does not show up automatically is because it requires REST enabled to display. By default, show_in_rest is set to false when registering taxonomies and post types. There’s currently a Trac Ticket #42785 open to change this default functionality. So in short when registering a taxonomy while using the Block Editor you’ll need … Read more

JSON File in Gutenberg

You can accomplish this with the good ol’ wp_localize_script. Step 1: When you register your blocks script, you already will do something like this: wp_register_script( ‘my-awesome-block’, plugins_url(‘/blocks/dist/blocks.build.js’, __FILE__), array(‘wp-blocks’, ‘wp-element’,’wp-editor’,’wp-components’,’lodash’), filemtime(plugin_dir_path(__FILE__).’blocks/dist/blocks.build.js’) ); After this (within the same function) insert: //Do whatever to parse the json-file or get the categories, get them into a nice array … Read more

Gutenberg Multiple InnerBlocks

You can (at the moment) not use InnerBlocks more than once within a block. However, you can bypass this by using a template for your InnerBlocks that contain Blocks which support InnerBlocks instead, like the core/column block. Like this: wp.element.createElement(InnerBlocks, { template: [[‘core/column’,{},[[‘core/paragraph’,{‘placeholder’:’Inhalt linke Spalte’}]]],[‘core/column’,{},[[‘core/paragraph’,{‘placeholder’:’Inhalt rechte Spalte’}]]]], templateLock: “all”, allowedBlocks: [‘core/column’]}); Some time ago, i … Read more