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

Takes over the whole block output from PHP, which is what a block whose markup is too involved for Handlebars or the block builder's code editor needs.

`$result` arrives as `null`. Return anything else and Lazy Blocks skips the block's own code entirely, the theme template, the PHP output and the Handlebars template all included, and carries your string on to the wrapper handling. Return `null` and the block renders normally, which makes this the place to override one block without disturbing the rest. The check is `is_block_content_exists()`, so an empty string counts as no output and the block's own code still runs.

## Attributes

| Name               | Type               | Description                                                                                                   |
| ------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------- |
| `$result`          | **String \| null** | block output, `null` before any handler runs                                                                  |
| `$attributes`      | **Array**          | control values, already through [lzb/block_render/attributes](https://www.lazyblocks.com/docs/php-filters/lzb-block_render-attributes/) |
| `$render_location` | **String**         | `editor` or `frontend`                                                                                        |
| `$context`         | **Array \| null**  | block context from parent blocks                                                                              |

## Additional Filters

| Name                                     | Arguments                                          | Description                         |
| ---------------------------------------- | -------------------------------------------------- | ----------------------------------- |
| `lazyblock/BLOCK_SLUG/frontend_callback` | `$result, $attributes`                             | specific block in the frontend only |
| `lazyblock/BLOCK_SLUG/editor_callback`   | `$result, $attributes`                             | specific block in the editor only   |
| `lazyblock/BLOCK_SLUG/callback`          | `$result, $attributes, $render_location, $context` | specific block only                 |

The per-location variants take two arguments only.

## Usage

```php title="PHP"
function my_lzb_block_render_callback( $result, $attributes, $render_location, $context ) {
  // Render the latest posts block from PHP, and show a placeholder in the
  // editor instead of running the query on every keystroke.
  if ( 'lazyblock/latest-posts' !== $attributes['lazyblock']['slug'] ) {
    return $result;
  }

  if ( 'editor' === $render_location ) {
    return '<div useBlockProps>Latest posts render on the front end.</div>';
  }

  $posts = get_posts( array( 'numberposts' => (int) $attributes['count'] ) );
  $items = '';

  foreach ( $posts as $post ) {
    $items .= '<li><a href="' . esc_url( get_permalink( $post ) ) . '">' . esc_html( $post->post_title ) . '</a></li>';
  }

  return '<ul useBlockProps>' . $items . '</ul>';
}

add_filter( 'lzb/block_render/callback', 'my_lzb_block_render_callback', 10, 4 );
```

The string is not escaped for you, so escape every value you interpolate. Include a `useBlockProps` attribute on your outer tag, as above. Without one, Lazy Blocks wraps the output in a `<div useBlockProps>` of its own, and that div, rather than your element, is what carries the block's classes, anchor and alignment on the front end. On the front end a block that returns nothing here and has no code of its own renders as nothing at all, and WordPress emits no wrapper for it.

Returning markup from the block builder instead is covered in [PHP Callback](https://www.lazyblocks.com/docs/blocks-code/php-callback/).

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