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

How to know whether you are editing a page or a post?

You can use the admin_body_class hook to add your own CSS classes. For example (if you’re using Gutenberg): function pb_admin_body_class($classes) { $screen = get_current_screen(); if (!$screen->is_block_editor()) { return $classes; } $post_id = isset($_GET[‘post’]) ? intval($_GET[‘post’]) : false; $post_type = get_post_type($post_id); if ($post_type) { $classes .= $post_type; } return $classes; } add_filter(‘admin_body_class’, ‘pb_admin_body_class’);