---
title: "lzb/register_blocks"
description: "lzb/register_blocks changes the block list the editor registers blocks from. Add a key here to read it in JavaScript, or hide a block from the inserter."
url: "https://www.lazyblocks.com/docs/php-filters/lzb-register_blocks/"
lastUpdated: 2026-09-23
source: "php-filters/lzb-register_blocks.mdx"
---
# lzb/register_blocks

Changes the block list the editor registers from, which is where a key has to be added for a JavaScript handler to read it back.

The result is localised as `window.lazyblocksGutenberg.blocks` and the editor loops over it calling `registerBlockType()`. It is the browser-side twin of [lzb/register_block_type_data](https://www.lazyblocks.com/docs/php-filters/lzb-register_block_type_data/), which shapes the same blocks for PHP. Only some keys are read directly. `title`, `description`, `icon`, `category`, `keywords`, `supports`, `condition` and `slug` build the registration arguments, and the whole item is handed to the block's edit component, so a key nothing in the editor knows about is still readable from the block data there.

## Attributes

| Name      | Type      | Description                                                                                      |
| --------- | --------- | ------------------------------------------------------------------------------------------------ |
| `$blocks` | **Array** | list of blocks, each one shaped like [lzb/block_data](https://www.lazyblocks.com/docs/php-filters/lzb-block_data/) returns |

`slug` is the full block name including the namespace and is what `registerBlockType()` is called with. `id` is the post ID, an integer, so match on `slug` rather than on `id` when picking one block out of the list. Lazy Blocks Pro adds `provides_context`, `uses_context`, `allowed_blocks` and `ancestor` here through its Relationships feature, and the JavaScript filter `lzb.registerBlockType.args` copies them onto the registration arguments.

## Usage

```php title="PHP"
function my_lzb_register_blocks( $blocks ) {
  // Let one block sit only inside a Group, and only take paragraphs.
  foreach ( $blocks as $key => $block ) {
    if ( 'lazyblock/faq-item' !== $block['slug'] ) {
      continue;
    }

    $blocks[ $key ]['ancestor']       = array( 'core/group' );
    $blocks[ $key ]['allowed_blocks'] = array( 'core/paragraph', 'core/heading' );
  }

  return $blocks;
}

add_filter( 'lzb/register_blocks', 'my_lzb_register_blocks' );
```

`ancestor` and `allowed_blocks` are read by the Pro Relationships script, so they do nothing without Pro. The list is JSON encoded for the browser, which turns a gapped array into an object and leaves the editor with no blocks at all, so reindex with `array_values()` after removing an item. Removing a block here hides it from the inserter but leaves it registered in PHP, so existing posts still render it.

The JavaScript side of the same registration is [lzb.registerBlockType.args](https://www.lazyblocks.com/docs/js-filters/lzb-registerblocktype-args/).

## 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
