Skip to content

Instantly share code, notes, and snippets.

@rayhanuddin2019
Forked from knuch/functions.php
Created June 2, 2022 04:33
Show Gist options
  • Save rayhanuddin2019/7806f9400696f19b2e903654d17ce327 to your computer and use it in GitHub Desktop.
Save rayhanuddin2019/7806f9400696f19b2e903654d17ce327 to your computer and use it in GitHub Desktop.
Gutenberg override core block
<?php
// https://developer.wordpress.org/reference/hooks/render_block/
add_filter( 'render_block', 'foo_core_gallery_filter', 10, 3);
function foo_core_gallery_filter( $block_content, $block ) {
// use blockName to only affect the desired block
if( "core/calendar" !== $block['blockName'] ) {
return $block_content;
}
// $block_content contains all the data passed to the block callback function
// $block contains the serialized block markup
// Here you have all content over the block. Either wrap it in your container or totally replace the content
$output = '<h2 class="foo-gallery">';
$output .= 'GALLERY';
$output .= '</h2>';
// return the new content of the block
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment