Skip to content

Functions

Get a translation by its key. Additional arguments are interpolated as dynamic values in the string.

Returns: string

ParamTypeDescription
keystringTranslation key
…valuesstringDynamic values to interpolate
{{ translate('hello_world') }}
{{ translate('hello_world', 'dynamic', 'strings') }}

Get all available languages.

Returns: array of language objects

{{ i18n_all() }}

Get the current language name.

Returns: string

{{ i18n_current() }}

Get the current language locale code (e.g. en_US).

Returns: string

{{ i18n_current_code() }}

Get all languages except the current one.

Returns: array of language objects

{{ i18n_other() }}

Check whether the given locale code is the active language.

Returns: bool

ParamTypeDescription
codestringLocale code to check (e.g. nl_NL)
{{ i18n_is('nl_NL') }}

Formats a locale code, normalizing region variants (e.g. en_GB → en_EN).

Returns: string

ParamTypeDescription
codestringLocale code to format (e.g. nl_NL)
{{ i18n_format_code('nl_NL') }}

Render a facet created with the FacetWP plugin.

Returns: void (outputs HTML directly)

ParamTypeDescription
namestringFacet machine name as defined in FacetWP
{{ facet_wp('facet_name') }}

Generate a nonce value for an AJAX action. Pass the result as a data-nonce attribute on your trigger element.

Returns: string

ParamTypeDescription
actionstringAJAX action route in dot notation (e.g. ajax.actions.my-action)
{{ nonce_ajax('ajax.actions.my-action') }}

Start a Query Monitor profiling session.

Returns: void

ParamTypeDescription
namestringUnique identifier for this session
{{ qm_start('unique_name') }}

Stop a previously started profiling session.

Returns: void

ParamTypeDescription
namestringMust match the name passed to qm_start
{{ qm_stop('same_name_as_qm_start') }}

Record a lap time on a running profiling session without stopping it.

Returns: void

ParamTypeDescription
namestringMust 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

TypeExample
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.


Render an HTML attribute string. If value is empty the attribute is omitted entirely.

Returns: string

ParamTypeDescription
namestringAttribute name
valuestringAttribute value — omitted if empty
conditionboolOptional. 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 ""

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

ParamTypeDescription
templatestringTemplate name (contact) or path (templates/contact.php)
{% set contactUrl = page_template_permalink('contact') %}
{% if contactUrl %}
<a href="{{ contactUrl }}">Contact</a>
{% endif %}

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

ParamTypeDescription
messagestringWhat is wrong
{% if image is not defined %}
{{ template_error('partials/image.twig: `image` is required') }}
{% endif %}