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 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

How to grab posts in Gutenberg Block?

You’ll need to use the REST API. You can access the latest posts by calling: wp.apiFetch( { path: ‘/wp/v2/posts’ } ).then( posts => { console.log( posts ); } ); Here is some more information on using the package – https://developer.wordpress.org/block-editor/packages/packages-api-fetch/

How to add a class to the element in a custom Gutenberg block

That documentation is for the base ButtonBlockAppender component in the @wordpress/block-editor package, and that component is exported with the name ButtonBlockerAppender (note the “Blocker” vs “Block”). But your code is actually using InnerBlocks.ButtonBlockAppender which is an enhanced version of that base ButtonBlockAppender component, and as of writing, that enhanced version does not include the className … Read more

Is there a way to set the gutenberg color palette outside the theme?

Yes, you have to use the init hook if you want to use add_theme_support from a plugin. I’ve tested the below code as a plugin and worked for me. <?php /* Plugin name: Add Color Palette */ function mytheme_setup_theme_supported_features() { add_theme_support(‘editor-color-palette’, array( array( ‘name’ => esc_attr__(‘Strong magenta’, ‘themeLangDomain’), ‘slug’ => ‘strong-magenta’, ‘color’ => ‘#a156b4’, ), … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)