Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Remove WordPress Gutenberg block in content
function remove_block_gutenberg( $content, $blockname ) {
$blockname = str_replace('/', '\/',preg_quote($blockname));
return preg_replace('/\<\!\-\- ' . $blockname . '[^)]+\/' . $blockname . ' \-\-\>/', '', $content);
// Based on this ticket
// There is a block that we don't want on excerpt automatically generated,
// Automatic excerpt cut the content and this can generate a broken content
// This happens because blocks can be everything from html, json or html comments and they are in the post_content
// If you want to know more about the wrong technicial decisions in Gutenberg
// *
// *
$content = remove_block_gutenberg(get_the_content(), 'wp:uagb/table-of-contents');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment