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

Gutenberg add extra attributes to custom format

I was able to add the attribute by passing it in attributes through the registerFormatType settings: attributes: { ‘custom-attr’: ‘custom-attr’ }, then in edit(): toggleFormat( value, { attributes: { ‘custom-attr’: ‘Hello world’ }, } ) I don’t know how exactly it all works together because I could not find detailed explanations in the current documentation. … Read more

var is undefined in a Gutenberg block

I think you have to pass in menu_selected edit: withAPIData( ( props ) => { return { menu_selected: `/menus/v1/menus/${ props.attributes.menu }` // custom endpoint }; } ) ( ( { menu_selected } ) => { I was able to do a very similar thing like so: edit: withAPIData( () => { return { posts: ‘/wp/v2/images?per_page=4&_embed’ … Read more

Instagram URL is converted into oEmbed

Figured it out. Embed shortcode stores the oemebd data as post meta using md5 hash. wp-includes/class-wp-embed.php // Check for a cached result (stored in the post meta) $key_suffix = md5( $url . serialize( $attr ) ); $cachekey = ‘_oembed_’ . $key_suffix; $cachekey_time=”_oembed_time_” . $key_suffix; And has a cache mechanism to fetch new data only after … Read more

Gutenberg – editor-font-sizes in functions not working

I believe to get this working I wasn’t calling this at the correct time, and I wrapped it in a function after_setup_theme, like so: add_action( ‘after_setup_theme’, ‘ttp_custom_font_sizes’ ); function ttp_custom_font_sizes() { // removes custom font sizes add_theme_support(‘disable-custom-font-sizes’); // add my own custom sizes add_theme_support( ‘editor-font-sizes’, array( array( ‘name’ => __( ‘Small’), ‘size’ => 12, ‘slug’ … Read more

Gutenberg get block name

From the props object we can get the block information. The object contains the name property you are looking for; this would be the code: const addClassName = createHigherOrderComponent(BlockListBlock => { return props => { if (props.name === “myplugin/myblock”) { return <BlockListBlock {…props} className=”test” />; } return <BlockListBlock {…props} />; }; }, “addClassName”); wp.hooks.addFilter( “editor.BlockListBlock”, … Read more