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

Filters the array handed to `lazyblocks()->add_template()`, before Lazy Blocks stores it.

A template registered from a theme is fixed in code, so a child theme or a plugin cannot widen its post types or change its lock. This filter is the place to do that.

## Attributes

| Name    | Type      | Description                                  |
| ------- | --------- | -------------------------------------------- |
| `$data` | **Array** | template data, as passed to `add_template()` |

`$data` takes the same keys a template read from the database has:

| Name            | Type       | Description                                                                       |
| --------------- | ---------- | --------------------------------------------------------------------------------- |
| `id`            | **Int**    | post ID, absent for a template registered from PHP                                |
| `title`         | **String** | template name shown on the Templates screen                                       |
| `post_types`    | **Array**  | post type slugs the template applies to                                           |
| `template_lock` | **String** | `all`, `insert`, or an empty string for no lock                                   |
| `blocks`        | **Array**  | block template array, each entry `array( 'core/heading', array( 'level' => 2 ) )` |

## Usage

```php title="PHP"
function my_lzb_add_user_template( $data ) {
  if ( ! isset( $data['title'] ) || 'Landing Page' !== $data['title'] ) {
    return $data;
  }

  // Reuse the landing page template on the `page` post type as well,
  // and stop editors from inserting blocks that are not in it.
  $data['post_types'][]   = 'page';
  $data['template_lock'] = 'insert';

  return $data;
}

add_filter( 'lzb/add_user_template', 'my_lzb_add_user_template' );
```

`register_post_type_args()` reads `post_types`, `blocks` and `template_lock` for every post type WordPress registers, not only for the Lazy Blocks ones, so dropping one of those keys throws an undefined-index warning on every `register_post_type()` call on the site. Lazy Blocks keeps its own callback here at priority 10, converting the pre-2.5.0 `data` sub-array: `data.post_type` becomes the `post_types` array, `data.template_lock` becomes `template_lock`, and each `array( 'name' => 'core/paragraph' )` entry becomes `array( 'core/paragraph' )`.

Templates are deprecated since v4.0.0, see [Templates](https://www.lazyblocks.com/docs/templates/).

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