Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnstonphilip/ae9b51a499c31338dad31aba278771c8 to your computer and use it in GitHub Desktop.
Save johnstonphilip/ae9b51a499c31338dad31aba278771c8 to your computer and use it in GitHub Desktop.
<?php
/**
* Modify the rendered output of any block.
*
* @param string $block_content The normal block HTML that would be sent to the screen.
* @param array $block An array of data about the block, and the way the user configured it.
*/
function my_custom_render( $block_content, $block ) {
// For the block in question, render whatever you want, and pull any attribute you need from $block['attrs'].
if ( $block['blockName'] === 'core/image' ) {
return 'Anything I want with any attribute value here: ' . $block['attrs']['name_of_attribute_here'] . '.';
}
// For any other block, just return normal block output.
return $block_content;
}
add_filter( 'render_block', 'my_custom_render', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment