Is it possible to create column width presets in Gutenberg?

Just in case anyone else comes looking here’s what I did. First I enqueued a javascript file into the block editor. add_action( ‘enqueue_block_editor_assets’, function () { wp_enqueue_style( ‘block-editor-styles’, get_template_directory_uri(‘styles/gutenberg.css’), false, ‘1.0’, ‘all’ ); wp_enqueue_script( ‘block-editor-scripts’, get_template_directory_uri(‘scripts/gutenberg.js’), array( ‘wp-blocks’, ‘wp-dom’ ), time(), true ); }); Then I just used this bit of code for adding a … Read more

How do I fire a snackbar notice in admin?

WordPress has some global actions you can use here. If you want to add your own notice in the lower corner (like the screenshot), you can do that like this: wp.data.dispatch(“core/notices”).createNotice( “success”, // Can be one of: success, info, warning, error. “This is my custom message.”, // Text string to display. { type: “snackbar”, isDismissible: … Read more

fetching via fetch/ajax gutenberg block data from third party

Well, I figured it out. Though my solution is probably far from elegant (I’m not making concessions for timeouts or usability/accessibility). My problem was mostly overzealous configuration, copy and paste errors, and needing to apply async/await keywords. Attributes look like this: attributes: { url: { source: ‘attribute’, type: ‘string’, selector: ‘.o_microlink’, attribute: ‘href’, }, title: … Read more

Get blocks from other pages, from within current page

WordPress provides a way to get an array of blocks for a page with the parse_blocks() function. If you extract from that the specific block(s) you are interested in, you can then use render_block() to put the block on another page. This function would do that: function example_extract_block_type_from_page( $post_id, $block_name ) { //get post_content for … Read more

Custom Gutenberg block is not showing up in inserter dialog

You should enqueue your scripts using enqueue_block_assets action, like this: add_action(‘enqueue_block_assets’, ‘gutenberg_bolierplate_block’); Second, you should use JSX with modern JavaScript development environment to write your blocks easily. I made a boilerplate for my personal use that you can use: https://github.com/HardeepAsrani/gutenberg-boilerplate You just need to run npm install to install dependencies, and then npm run dev … Read more