Can the index.asset.php file be used with the enqueue_block_editor_assets action?

Yes you can use the index.asset.php file in the ‘enqueue_block_editor_assets’ action. I guess you missed to npm install the dependencies you want to use and import them in your script. That’s how @wordpress/scripts generates your asset.php file. If you do not import the dependencies in your JavaScript files the dependency management of asset.php wont work. … 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’);

InnerBlocks breaks Flexbox and CSS Grid styles

You can eliminate the wrapping containers abandoning InnerBlocks and instead using the useInnerBlocksProps hook which is how the blocks that come with core do it. This will allow your block markup to match the frontend without the editor wrapping things in additional tags. If we look at the official buttons block: import { BlockControls, useBlockProps, … Read more

Adding an html wrapper to a custom Block Pattern

The group block comes to mind as an out of the box pattern wrapper with a custom class mywrapper: <!– wp:group {“className”:”mywrapper”} –> <div class=”wp-block-group mywrapper”><div class=”wp-block-group__inner-container”> …pattern… </div></div> <!– /wp:group –> Theoretically one can use the custom html block as a pattern, like: <!– wp:html –> <div class=”mywrappper”> <h1 class=”has-text-align-center”>Block 1</h1> <h2 class=”has-text-align-center”>Block 2</h2> … Read more

Limit Gutenberg blocks available to users to choose from

In the functions.php file I added add_filter( ‘allowed_block_types_all’, ‘func_allowed_block_types’ ); function func_allowed_block_types( $allowed_blocks ) { return array( ‘core/embed’ ); } Then in my plugin I added this JS to the javascript file to enable only the embed blocks I wanted (Twitter, youTube and Vimeo) wp.domReady( function() { const allowedEmbedBlocks = [ ‘twitter’,’youtube’, ‘vimeo’ ]; wp.blocks.getBlockType( … Read more

Custom button block doesn’t work

I’d recommend looking at how the existing Button component works to get a sense of how Gutenberg does things. Specifically it uses a <RichText/> component (instead of a native <input>) which allows you to specify the tag name while also supporting user input. Generally I’d advice against using <input> elements whenever possible. WordPress makes available … Read more