Skip to content
PHP Filters

lzb/block_render/attributes

Supplies a value the template needs but no control stores, such as the current post's terms or a price pulled from another table.

It is the first filter in the render pipeline. Every control value has already been resolved and passed through lzb/control_value by this point, and nothing has been rendered yet, so an attribute added here is visible to the PHP template, to the Handlebars template and to the theme template file alike.

Attributes

NameTypeDescription
$attributesArraycontrol values keyed by control name, plus the reserved lazyblock, className, anchor, blockId and blockUniqueClass
$contentString | nullinner blocks markup, null when the block has none
$blockArrayblock data, the same array lzb/block_data returns
$render_locationStringeditor or frontend
$contextArray | nullblock context from parent blocks

$context is null for an ordinary render. It only carries values when the block declares uses_context through the Pro Relationships feature, or when the render comes from the editor preview REST route.

Additional Filters

NameArgumentsDescription
lazyblock/BLOCK_SLUG/frontend_attributes$attributes, $content, $block, $contextspecific block in the frontend only
lazyblock/BLOCK_SLUG/editor_attributes$attributes, $content, $block, $contextspecific block in the editor only
lazyblock/BLOCK_SLUG/attributes$attributes, $content, $block, $render_location, $contextspecific block only

The per-location variants take four arguments, not five. They already know the render location from their own name, so $context moves into the fourth position.

Usage

PHP
function my_lzb_block_render_attributes( $attributes, $content, $block, $render_location, $context ) {
  // Give the recipe block the current post's cuisine terms, which no
  // control stores.
  if ( 'lazyblock/recipe' !== $block['slug'] ) {
    return $attributes;
  }
 
  $attributes['cuisines'] = wp_get_post_terms( get_the_ID(), 'cuisine', array( 'fields' => 'names' ) );
 
  return $attributes;
}
 
add_filter( 'lzb/block_render/attributes', 'my_lzb_block_render_attributes', 10, 5 );

The return value has to be an array, because the render callback indexes into it straight afterwards. An attribute added here exists only during the render. It is not registered with register_block_type(), so the editor never saves it and Gutenberg never validates it. Removing a key that a control declared leaves the template reading an undefined index instead of an empty string.

To change the finished markup rather than its inputs, use lzb/block_render/output.

Was this article helpful?

Copyright © 2026 Lazy Blocks.