Dynamic Gutenburg block output echoes in WP Dashboard

Excerpt from “Creating dynamic blocks” in the block editor handbook: The server-side rendering is a function taking the block and the block inner content as arguments, and returning the markup (quite similar to shortcodes) So despite the “render” as in render_callback, a block render callback should not actually echo anything (and neither call any functions … Read more

Notices in the Block Editor with multiple lines

The 3rd parameter for the function accepts a private option named __unstableHTML which if true, then enables HTML in the notice message/content: createNotice( ‘success’, ‘Post published.<br /> Line 2. Should work in WordPress 5.8.’, { __unstableHTML: true, // true = allows HTML; default false isDismissible: true, actions: [ … ], } ) However, in the … Read more

Gutenberg Button Border Radius Default

This should theoretically work by defining the initial value in theme.json as shown in these examples https://gist.github.com/skorasaurus/d50ea7eb79d664775418492e46cef021 and https://github.com/WordPress/theme-experiments/blob/304e6ef3d561f048c87d9bc27311328ae8197bae/tt1-blocks/theme.json#L276 however, the value is still unset when I tried it out in a theme and it appears they may have disabled it – https://github.com/WordPress/gutenberg/issues/29210

How to set Gutenberg preferences programmatically with wp.data.dispatch?

This correctly shows true/false when the option for Reduce the interface is enabled/disabled through the GUI. Are you sure isFeatureActive( ‘reduceInterface’ ) worked? Because I looked at the source code (see wp-includes/js/dist/edit-post.js) and then I found out that the feature name is actually reducedUI and not reduceInterface. So try with reducedUI instead: let reduceInterface = … Read more

Gutenberg: How to check if a block is used in a paginated post?

The solution is simple: has_block( ‘simpetoc/toc, $YOUR_POSTS_CONTENT_OR_POST_ID ) https://developer.wordpress.org/reference/functions/has_block/ has_block( string $block_name, int|string|WP_Post|null $post = null ) There is no need to render the blocks to build a table of contents, nor should you do it that way. Note that your current approach breaks user defined HTML anchors and doesn’t account for headings in nested … Read more