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

Runs after one block template has been imported from a JSON file, which is where an imported template gets pointed at the post types this site actually has.

It fires at the end of `import_template()`, once the `lazyblocks_templates` post exists and its four metas have been written. Import stops before this point when a template for any of the same post types is already registered, so the action only fires for templates that were created. A file holding several templates fires it once per template.

## Attributes

| Name       | Type      | Description                             |
| ---------- | --------- | --------------------------------------- |
| `$post_id` | **Int**   | post ID of the template just created    |
| `$data`    | **Array** | the template as it appeared in the file |

`$data` has `id`, `title`, `post_types`, `blocks` and `template_lock`. `id` is the post ID from the site the template was exported from. The metas written from it are `_lzb_template_post_types`, `_lzb_template_blocks` (URL encoded JSON), `_lzb_template_lock` and `_lzb_template_convert_blocks_to_content`, which the importer sets to `true` while the template editor's own default is `false`.

## Usage

```php title="PHP"
function my_lzb_import_template( $post_id, $data ) {
  // The export was made on a site with a "case-study" post type this one
  // calls "project". Retarget the template instead of failing quietly.
  $post_types = array_map(
    function ( $type ) {
      return 'case-study' === $type ? 'project' : $type;
    },
    (array) $data['post_types']
  );

  update_post_meta( $post_id, '_lzb_template_post_types', $post_types );
}

add_action( 'lzb/import/template', 'my_lzb_import_template', 10, 2 );
```

`_lzb_template_post_types` is an array of post type slugs, and a template pointing at a post type that does not exist is simply never applied, with no notice anywhere. `_lzb_template_blocks` has to stay URL encoded JSON, so run any replacement through `rawurlencode( wp_json_encode( ... ) )` the way the importer does.

To rewrite the payload before any post is inserted, use [lzb/import_json](https://www.lazyblocks.com/docs/php-filters/lzb-import_json/). The block equivalent of this action is [lzb/import/block](https://www.lazyblocks.com/docs/php-actions/lzb-import-block/), and templates themselves are covered in [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
