Last active
June 14, 2022 18:08
-
-
Save johnstonphilip/ae9b51a499c31338dad31aba278771c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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