Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use the `render_block` filter to show the elemental parts of a WordPress block.
<?php
add_filter( 'render_block', 'show_the_block_constituents', 10, 2 );
/**
* [show_the_block_constituents] Debug code for showing the parts of WP Blocks
*
* @param [string] $block_content
* @param [array] $block
* @return [string]
*/
function show_the_block_constituents( $block_content, $block ) {
if ( true === WP_DEBUG && current_user_can( 'administrator' ) ) {
$block_content = "<div class='wp-block' data-blockType='{$block['blockName']}'>{$block_content}</div>" . ( 'string' === gettype( $block['blockName'] ) ? '<pre><xmp> $block_content = ' . gettype( $block_content ) . " {$block['blockName']} " . print_r( $block, true ) . '</xmp></pre>' : '' );
}
return $block_content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment