Dynamic blocks

PHP block templates

Render attributes safely while keeping markup in your theme.

#Template contract

The template runs inside the render callback and receives $attributes. It must be a PHP file below WP_CONTENT_DIR or another explicitly trusted root.

PHP
<?php
$heading = (string) ($attributes['heading'] ?? '');
$image   = (array) ($attributes['image'] ?? []);
?>
<section <?= get_block_wrapper_attributes(['class' => 'hero']) ?>>
    <h2><?= esc_html($heading) ?></h2>
    <?= wp_get_attachment_image((int) ($image['id'] ?? 0), 'full') ?>
</section>

#Escape for the output context

ContextFunction
Visible textesc_html()
HTML attributeesc_attr()
URLesc_url()
Trusted rich HTMLwp_kses_post()
Attachment imagewp_get_attachment_image()

#Additional trusted roots

PHP
add_filter('voxycure_template_roots', function (array $roots): array {
    $roots[] = '/srv/shared-wordpress-templates';
    return $roots;
});
Framework version2.0.0
PHP requirement8.0+
Documentation updatedAugust 2026