---
title: "lzb/block_data"
description: "PHP filter `lzb/block_data` of the Lazy Blocks WordPress plugin."
url: "https://www.lazyblocks.com/docs/php-filters/lzb-block_data/"
lastUpdated: 2026-09-09
source: "php-filters/lzb-block_data.mdx"
---
# lzb/block_data

Adds a key to a block after Lazy Blocks has assembled it from post meta, which is how a custom setting saved on the block builder screen reaches the rest of the plugin.

It fires once per block inside `marshal_block_data_with_controls()`, for blocks created in the builder and for blocks registered from PHP alike. Everything downstream reads the array this filter returns, so a key added here is visible to the render callback, to `register_block_type()` and to the editor. Lazy Blocks Pro uses it for exactly this. The Relationships feature adds `provide_context_to_blocks`, `custom_context_slug`, `allowed_blocks` and `ancestor` at priority 12, and the custom slug namespace feature rewrites `slug` at priority 10.

## Attributes

| Name              | Type         | Description                                     |
| ----------------- | ------------ | ----------------------------------------------- |
| `$block_data`     | **Array**    | assembled block, see the keys below             |
| `$get_meta_value` | **Callable** | reads one raw meta value for this block by name |

| Key              | Type            | Description                                                                                                                                                              |
| ---------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `id`             | **Int \| null** | post ID, `null` for a block registered from PHP                                                                                                                          |
| `title`          | **String**      | block name in the inserter                                                                                                                                               |
| `icon`           | **String**      | SVG markup or a Dashicons name                                                                                                                                           |
| `keywords`       | **Array**       | extra inserter search terms                                                                                                                                              |
| `slug`           | **String**      | full block name, for example `lazyblock/alert-block`                                                                                                                     |
| `description`    | **String**      | text under the block name in the inspector                                                                                                                               |
| `category`       | **String**      | sanitised category slug                                                                                                                                                  |
| `category_label` | **String**      | category name as typed in the builder                                                                                                                                    |
| `supports`       | **Array**       | `customClassName`, `anchor`, `html`, `multiple`, `inserter`, `reusable`, `color`, `layout`, `shadow`, `spacing`, `dimensions`, `typography`, `lock`, `align`, `ghostkit` |
| `controls`       | **Array**       | controls keyed by control ID, already merged with their type defaults                                                                                                    |
| `code`           | **Array**       | `output_method`, `editor_html`, `editor_callback`, `frontend_html`, `frontend_callback`, `show_preview`, `single_output`                                                 |
| `style`          | **Array**       | `block` and `editor` CSS strings                                                                                                                                         |
| `script`         | **Array**       | `view` JavaScript string                                                                                                                                                 |
| `styles`         | **Array**       | block style variations                                                                                                                                                   |
| `condition`      | **Array**       | post types the block is limited to                                                                                                                                       |
| `edit_url`       | **String**      | block builder link for this block                                                                                                                                        |

`$get_meta_value` takes one raw meta name and returns its value with the block defaults already applied, so `$get_meta_value( 'lazyblocks_slug' )` gives the slug without the namespace.

## Usage

```php title="PHP"
function my_lzb_block_data( $block_data, $get_meta_value ) {
  // Surface a meta field added by a custom block builder panel, so the
  // render callback and register_block_type() can both see it.
  $block_data['my_wrapper_tag'] = $get_meta_value( 'lazyblocks_my_wrapper_tag' );

  if ( ! $block_data['my_wrapper_tag'] ) {
    $block_data['my_wrapper_tag'] = 'div';
  }

  return $block_data;
}

add_filter( 'lzb/block_data', 'my_lzb_block_data', 10, 2 );
```

`get_blocks()` caches its result in a transient for a day. The cache key is a hash that counts the priorities registered on this filter, so adding a handler at a priority nothing else uses invalidates the cache on its own, while a second handler at priority 10 lands in an existing bucket and keeps serving stale data until [lzb/cache_expiration](https://www.lazyblocks.com/docs/php-filters/lzb-cache_expiration/) runs out or a block is saved. Dropping the `slug` key removes the block from the editor entirely, because `register_block()` filters out blocks whose slug has no name after the namespace.

The neighbouring stages are [lzb/block_defaults](https://www.lazyblocks.com/docs/php-filters/lzb-block_defaults/) for the fallback values, [lzb/prepare_block_attribute](https://www.lazyblocks.com/docs/php-filters/lzb-prepare_block_attribute/) for one control's attribute, and [lzb/register_block_type_data](https://www.lazyblocks.com/docs/php-filters/lzb-register_block_type_data/) for the registration array.

## Documentation Index
> Fetch the complete documentation index at: https://www.lazyblocks.com/llms.txt
> Fetch every page in a single file at: https://www.lazyblocks.com/llms-full.txt
