How to get custom page template being edited in gutenberg editor

You can use this code once set page template for specific post. If the template isn’t set, you cant enqueue your script. if ( $post->_wp_page_template === ‘sky-template.php’ ) { wp_enqueue_script(); } Remember to replace sky-template.php with your template file name. Edit: You can get some help from this question. _wp_page_template to dynamically use template

Filter root element of tag cloud block

Figured it out myself after all. Instead of using the pre_render_block filter, use the render_block filter to do something like this: add_filter(‘render_block’, function($html, $block) { if ($block[‘blockName’] !== ‘core/tag-cloud’) { return $html; } $doc = new \DOMDocument($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $ps = iterator_to_array($doc->getElementsByTagName(‘p’)); $p = empty($ps) ? new \DOMElement(‘p’) : current($ps); return replaceChild($doc, $p, ‘div’, … Read more

How to limit the selection of the first level block in Gutenberg editor

Create a new custom block, lets call it CustomSecondary, that contains an InnerBlocks instance. When registering this block set it’s parent property to your main custom block and registerBlockType( ‘custom-secondary’, { parent: [‘your-main-block], edit: () => ( <InnerBlocks />) { .. your other properties } }); This will make it so this block can only … Read more