elementor-dynamic-tag-fields
Elementor: Dynamic Tag types, fields & fallback
The body of a dynamic tag has three decisions: which base class (Tag vs Data_Tag), which categories it produces (so the right controls accept it), and which settings fields the editor shows. Plus the easily-missed fallback asymmetry between the two base classes. This skill assumes the tag is already being registered — see elementor-dynamic-tag-register for that.
Decision 1 — Tag vs Data_Tag
Tag |
Data_Tag |
|
|---|---|---|
| Extend | \Elementor\Core\DynamicTags\Tag |
\Elementor\Core\DynamicTags\Data_Tag |
| You implement | render() — echo the output |
get_value( array $options = [] ) — return the value |
get_content_type() |
'ui' (final) |
'plain' (final) |
| Use for | rendered text/HTML fragments (price, reading time, a badge) | structured values consumed by a control — an image array [ 'id' => …, 'url' => … ], a URL string, a color |
Verified: Tag::get_content() does ob_start(); $this->render(); $value = ob_get_clean(); (tag.php:30-37) and get_content_type() returns 'ui' (tag.php:64). Data_Tag declares abstract protected function get_value() (data-tag.php:25), returns it directly from get_content() (data-tag.php:43-45), and get_content_type() returns 'plain' (data-tag.php:31).
Rule of thumb: if the value feeds a MEDIA / IMAGE / URL / COLOR control (the control needs a structured value, not printed markup), use Data_Tag. If it feeds a TEXT context (it's printed inline), use Tag.