Filter Gutenberg Blocks Content

Have you tried using parse_blocks() (pass in get_the_content())? That returns an array of all the blocks in your content. From there you can pull out block names and id attributes using an array map or foreach. Assuming you only want to pull anchor tags from the headings, you could do something like: $blocks = parse_blocks( … Read more

Gutenberg First Block on Page Conditional?

Here’s a solution I’ve come up with, that works with WordPress 5.4 and ACF Pro 5.8.9. First you need this function somewhere in functions.php: /** * Get ID of the first ACF block on the page */ function sg_get_first_block_id() { $post = get_post(); if(has_blocks($post->post_content)) { $blocks = parse_blocks($post->post_content); $first_block_attrs = $blocks[0][‘attrs’]; if(array_key_exists(‘id’, $first_block_attrs)) { return … Read more

Your site doesn’t include support for the block… after registering a block

The js-file is not executed on time By the time the DOM load event is executed the block editor has already parsed the post content and at that time the block wasn’t yet registered so it tells you that it doesn’t exist. Instead of: window.addEventListener( ‘load’, () => { mcm_register_menu_card_section_block(); }); try: wp.domReady(mcm_register_menu_card_section_block); and in … Read more

Add product attribute to Woocommerce’s blocks in Gutenberg

As the blocks more more and more to front-end rendering… there’s only one filter that I’ve been able to find for modifying the output of the blocks via PHP. woocommerce_blocks_product_grid_item_html and I’m not even sure if that will work on the All Products block which may/may not use the same code as the other products … Read more