Writing Element Templates
The WPCE is intentionally unopinionated about the tools you can use to render elements. Therefore it provides a very low-level way to generate element HTML: A WordPress filter. If needed, you can build your own abstractions on top of that.
An element's output can be created using the wpce_render_{$element_id} filter. The filter will be applied with the $wpce and $element parameters, which correspond to the rendering WPCE instance and the current element node.
The rendered elements' properties can be accessed via $element->properties:
php
$element_id = 'my-element';
add_filter(
"wpce_render_{$element_id}",
fn ($wpce, $element) => <<<HTML
<div class="my-element">{$element->properties->prop_name}</div>
HTML,
10,
2
);TIP
- Learn more about using filters in the WordPress Developer Handbook.
- Some basic templating patterns and helpers are documented in the Cookbook.