Functions
translate
Section titled “translate”Get a translation by its key. Additional arguments are interpolated as dynamic values in the string.
Returns: string
| Param | Type | Description |
|---|---|---|
| key | string | Translation key |
| …values | string | Dynamic values to interpolate |
{{ translate('hello_world') }}{{ translate('hello_world', 'dynamic', 'strings') }}i18n_all
Section titled “i18n_all”Get all available languages.
Returns: array of language objects
{{ i18n_all() }}i18n_current
Section titled “i18n_current”Get the current language name.
Returns: string
{{ i18n_current() }}i18n_current_code
Section titled “i18n_current_code”Get the current language locale code (e.g. en_US).
Returns: string
{{ i18n_current_code() }}i18n_other
Section titled “i18n_other”Get all languages except the current one.
Returns: array of language objects
{{ i18n_other() }}i18n_is
Section titled “i18n_is”Check whether the given locale code is the active language.
Returns: bool
| Param | Type | Description |
|---|---|---|
| code | string | Locale code to check (e.g. nl_NL) |
{{ i18n_is('nl_NL') }}i18n_format_code
Section titled “i18n_format_code”Formats a locale code, normalizing region variants (e.g. en_GB → en_EN).
Returns: string
| Param | Type | Description |
|---|---|---|
| code | string | Locale code to format (e.g. nl_NL) |
{{ i18n_format_code('nl_NL') }}FacetWP
Section titled “FacetWP”facet_wp
Section titled “facet_wp”Render a facet created with the FacetWP plugin.
Returns: void (outputs HTML directly)
| Param | Type | Description |
|---|---|---|
| name | string | Facet machine name as defined in FacetWP |
{{ facet_wp('facet_name') }}nonce_ajax
Section titled “nonce_ajax”Generate a nonce value for an AJAX action. Pass the result as a data-nonce attribute on your trigger element.
Returns: string
| Param | Type | Description |
|---|---|---|
| action | string | AJAX action route in dot notation (e.g. ajax.actions.my-action) |
{{ nonce_ajax('ajax.actions.my-action') }}Query Monitor
Section titled “Query Monitor”qm_start
Section titled “qm_start”Start a Query Monitor profiling session.
Returns: void
| Param | Type | Description |
|---|---|---|
| name | string | Unique identifier for this session |
{{ qm_start('unique_name') }}qm_stop
Section titled “qm_stop”Stop a previously started profiling session.
Returns: void
| Param | Type | Description |
|---|---|---|
| name | string | Must match the name passed to qm_start |
{{ qm_stop('same_name_as_qm_start') }}qm_lap
Section titled “qm_lap”Record a lap time on a running profiling session without stopping it.
Returns: void
| Param | Type | Description |
|---|---|---|
| name | string | Must match the name passed to qm_start |
{{ qm_lap('same_name_as_qm_start') }}Build a space-separated class string from mixed inputs — strings, conditional expressions, arrays, and objects. Equivalent to the clsx utility in React.
Returns: string
{{ clsx('btn', isPrimary and 'btn-primary', ['btn-large'], { 'active': isActive }) }}outputs "btn btn-primary btn-large active"Supported input types
| Type | Example |
|---|---|
| String | 'btn' |
Conditional (use and) | isActive and 'active' |
| Array | ['btn', 'btn-large'] |
| Associative array | { 'active': isActive } |
Falsy values (false, null, empty string) are ignored. Nested arrays are flattened.
html_attribute
Section titled “html_attribute”Render an HTML attribute string. If value is empty the attribute is omitted entirely.
Returns: string
| Param | Type | Description |
|---|---|---|
| name | string | Attribute name |
| value | string | Attribute value — omitted if empty |
| condition | bool | Optional. When false, attribute is not rendered regardless of value |
{{ html_attribute('data-src', image.src) }}outputs data-src="https://somesite/image.jpg"{{ html_attribute('data-src', image.src, true) }}outputs data-src="https://somesite/image.jpg"
{{ html_attribute('data-src', image.src, false) }}outputs ""Page templates
Section titled “Page templates”page_template_permalink
Section titled “page_template_permalink”Get the permalink of the first published page using a page template, e.g. to link to an overview page without hardcoding its URL.
Returns: string|null, null when no published page uses the template
| Param | Type | Description |
|---|---|---|
| template | string | Template name (contact) or path (templates/contact.php) |
{% set contactUrl = page_template_permalink('contact') %}
{% if contactUrl %} <a href="{{ contactUrl }}">Contact</a>{% endif %}template_error
Section titled “template_error”Report a misused partial, such as a required variable that is missing or invalid. With WP_DEBUG on it throws a Twig error that names the template and line. Without it, the message is logged to the PHP error log and the page keeps rendering.
Use it instead of silently falling back to a default, so mistakes surface during development.
Returns: nothing
| Param | Type | Description |
|---|---|---|
| message | string | What is wrong |
{% if image is not defined %} {{ template_error('partials/image.twig: `image` is required') }}{% endif %}
