Skip to content
PHP Filters

lzb_pro/block_style/template

Points a block at a stylesheet the theme does not carry, which is what a plugin shipping its own template blocks needs.

A block whose Output Method is Theme Template picks up two optional stylesheets next to its template, blocks/BLOCK-SLUG/block.css and blocks/BLOCK-SLUG/editor.css. find_style_template() resolves each name with locate_template(), fires this filter, and registers the file when file_exists() passes. Blocks using any other output method never reach it, because their CSS comes from the block builder's own style fields.

Attributes

NameTypeDescription
$templateStringpath found by locate_template(), empty when the theme has no such file
$template_nameStringname being looked up, blocks/BLOCK-SLUG/block.css or blocks/BLOCK-SLUG/editor.css
$blockArrayblock data, the same array lzb/block_data returns
$contextStringblock for the front end stylesheet, editor for the editor one

$context is not the render location. It names which of the two stylesheets is being resolved, so a handler that only wants to replace the front end file checks for block.

Additional Filters

NameArgumentsDescription
lazyblock/BLOCK_SLUG/block_style_template$template, $template_name, $blockone block's front end stylesheet
lazyblock/BLOCK_SLUG/editor_style_template$template, $template_name, $blockone block's editor stylesheet
lazyblock/BLOCK_SLUG/style_template$template, $template_name, $block, $contextone block, both stylesheets

Usage

PHP
function my_lzb_pro_block_style_template( $template, $template_name, $block, $context ) {
  // Ship the front end CSS with the plugin, and let the theme override it
  // by placing a file of the same name.
  if ( $template || 'block' !== $context ) {
    return $template;
  }
 
  $fallback = plugin_dir_path( __FILE__ ) . $template_name;
 
  return file_exists( $fallback ) ? $fallback : $template;
}
 
add_filter( 'lzb_pro/block_style/template', 'my_lzb_pro_block_style_template', 10, 4 );

Return an absolute filesystem path, not a URL. Lazy Blocks Pro reads the file's modification time to build a cache-busting version and then converts the path to a URL by matching it against the content, theme, child theme and plugin directories in that order. A file outside all of them falls back to matching against ABSPATH, and a path that matches nothing produces no stylesheet at all.

The script counterpart is lzb_pro/block_script/template. Where these files live is covered in Styles and Scripts.

Was this article helpful?

Copyright © 2026 Lazy Blocks.