How often do you write print_r( $something )
to see what’s in the variable? This works great, except it appears inline right where your code is executing.
My ea_pp()
function works the same way, but outputs it in a console-like box attached to the right side of the screen. This pretty printing function was originally built by Chris Bratlien.
Example
I was looking to see which attributes are included in the core/gallery
block, so I added the following code to functions.php:
add_action( 'wp_footer', function() {
global $post;
$blocks = parse_blocks( $post->post_content );
foreach( $blocks as $block ) {
if( 'core/gallery' === $block['blockName'] ) {
ea_pp( $block );
}
}
});
This displayed all the gallery block information on the right side of the screen:


Code
I include this in a mu-plugin locally so it only runs in my development environment, but you could also add it to a plugin or your theme’s functions.php file.
/**
* Pretty Printing
*/
function ea_pp( $obj, $label="" ) {
$data = json_encode( print_r( $obj,true ) );
?>
Leave a Reply