Filters
Filters transform data in expressions. Apply them with the pipe (|) operator.
{{ post.title|upper }}
{{ post.excerpt|truncate(100) }}
{{ post.content|striptags|excerpt(25) }}
String
| Filter | Example | Description |
|---|---|---|
upper | post.title|upper | Convert to uppercase |
lower | post.title|lower | Convert to lowercase |
capitalize | post.title|capitalize | Capitalize first letter |
title | post.title|title | Convert to title case |
trim | post.title|trim | Remove whitespace or characters |
truncate | post.excerpt|truncate(100) | Limit string length |
excerpt | post.content|excerpt(25) | Trim to word count |
excerpt_chars | post.content|excerpt_chars(200) | Trim to character count |
striptags | post.content|striptags | Remove HTML tags |
nl2br | post.content|nl2br | Newlines to <br> |
spaceless | html|spaceless | Remove whitespace between tags |
pretags | post.content|pretags | Escape HTML inside <pre> |
replace | post.title|replace('old', 'new') | Replace text |
split | 'a,b,c'|split(',') | Split into array |
slug | post.title|slug | URL-friendly slug |
sanitize | post.title|sanitize | Alias for slug |
format | '%s has %d posts'|format(user.name, count) | sprintf-style formatting |
url_encode | query|url_encode | URL encode |
relative | post.link|relative | Absolute URL to relative |
Number
| Filter | Example | Description |
|---|---|---|
number_format | 1234.5|number_format(2) | Format with decimals and separators |
number_i18n | 1234|number_i18n | Format using WordPress localization |
abs | -5|abs | Absolute value |
round | 4.567|round(1) | Round number |
Date
| Filter | Example | Description |
|---|---|---|
date | post.date|date('F j, Y') | Format date |
date_i18n | post.timestamp|date_i18n('F j, Y') | Format with WordPress localization |
date_modify | post.date|date_modify('+1 day') | Modify date |
time_ago | post.date|time_ago | Human-readable time difference |
Array
| Filter | Example | Description |
|---|---|---|
first | posts|first | First element |
last | posts|last | Last element |
join | names|join(', ') | Join into string |
list | names|list | Human-readable list (A, B and C) |
length | posts|length | Count elements |
keys | data|keys | Get keys |
values | data|values | Get values |
slice | posts|slice(0, 3) | Extract portion |
batch | items|batch(3) | Group into batches |
column | users|column('name') | Extract column |
merge | categories|merge(tags) | Merge arrays |
reverse | posts|reverse | Reverse order |
shuffle | posts|shuffle | Randomize order |
sort | items|sort | Sort |
filter | posts|filter(p => p.featured) | Keep matching elements |
map | posts|map(p => p.title) | Transform each element |
reduce | items|reduce((a, b) => a + b, 0) | Reduce to single value |
find | posts|find(p => p.featured) | Find first match |
array | value|array | Ensure value is array |
wp_list_filter | posts|wp_list_filter({status: 'publish'}) | Filter using wp_list_filter() |
WordPress
| Filter | Example | Description |
|---|---|---|
wpautop | post.content|wpautop | Add paragraph tags |
wptexturize | post.title|wptexturize | Smart quotes and dashes |
shortcodes | post.content|shortcodes | Process shortcodes |
stripshortcodes | post.content|stripshortcodes | Remove shortcodes |
antispambot | user.user_email|antispambot | Obfuscate email |
kses_post | post.meta('html_field')|kses_post | Output HTML (overrides default escaping) |
Utility
| Filter | Example | Description |
|---|---|---|
default | post.subtitle|default('No subtitle') | Fallback if empty |
json_encode | data|json_encode | Encode as JSON |
Intl
Requires the PHP intl extension.
| Filter | Example | Description |
|---|---|---|
country_name | 'US'|country_name | Country name from code |
currency_name | 'USD'|currency_name | Currency name from code |
currency_symbol | 'EUR'|currency_symbol | Currency symbol from code |
language_name | 'fr'|language_name | Language name from code |
locale_name | 'en_US'|locale_name | Locale name from code |
timezone_name | 'Europe/Paris'|timezone_name | Timezone name from identifier |
format_currency | price|format_currency('USD') | Format as currency |
format_number | 0.75|format_number('percent') | Format number |
format_date | post.date|format_date('long') | Localized date |
format_time | post.date|format_time('short') | Localized time |
format_datetime | post.date|format_datetime | Localized date and time |
WooCommerce
Requires WooCommerce.
| Filter | Example | Description |
|---|---|---|
currency | product.price|currency | Format as store currency via wc_price() |