Removing a custom block from content
<?php
add_filter('the_content', 'remove_to_do_from_content', 5);
function remove_to_do_from_content($content){
if (has_block('custom/todo') === false) {
return $content;
}
$parsed = parse_blocks($content);
foreach ($parsed as $index => $block) {
if ($block['blockName'] === 'custom/todo') {
unset($parsed[$index]);
}
}
return serialize_blocks($parsed);
}
Take a look at the third argument. Our filter has to be run before the build-in converter (Gutenberg -> HTML) so we have to set a priority to 5
.
We do not have break
after first found because we can have more than one todo block