PHP Callback
You can use custom PHP code to render Frontend and Editor blocks output. Each Lazy Block has a filter for custom output callback. This output will be used instead of Frontend Code and Editor Code in the block Constructor.
These callbacks helpful when you want to put block output code inside your custom plugin or inside the theme code (functions.php).
- Replace
my_block_slug
to your block name - Replace
my_block_output
to something unique, so it will not conflict with other functions
// filter for Frontend output.
add_filter( 'lazyblock/my_block_slug/frontend_callback', 'my_block_output', 10, 2 );
// filter for Editor output.
add_filter( 'lazyblock/my_block_slug/editor_callback', 'my_block_output', 10, 2 );
if ( ! function_exists( 'my_block_output' ) ) :
/**
* Test Render Callback
*
* @param string $output - block output.
* @param array $attributes - block attributes.
*/
function my_block_output( $output, $attributes ) {
ob_start();
?>
<div>
Control value: <?php echo esc_html( $attributes['test_control'] ); ?>
</div>
<?php
return ob_get_clean();
}
endif;
Frontend Output Wrapper
Lazy Blocks automatically add a wrapper to your frontend output code. If you want to add your own wrapper implementation with custom attributes, you can easily disable default wrapper for your block using this filter:
// disable block frontend wrapper.
add_filter( 'lazyblock/BLOCK_SLUG/frontend_allow_wrapper', '__return_false' );
Look at this code part to see what exactly added to the wrapper.
InnerBlocks Wrapper
Lazy Blocks automatically add a wrapper to the <InnerBlocks />
component. If you want to add your own wrapper implementation with custom attributes in the frontend code output, you can easily disable default wrapper for your inner blocks using this filter:
// disable <InnerBlocks /> wrapper.
add_filter( 'lazyblock/BLOCK_SLUG/allow_inner_blocks_wrapper', '__return_false' );