Skip to main content

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

FilterExampleDescription
upperpost.title|upperConvert to uppercase
lowerpost.title|lowerConvert to lowercase
capitalizepost.title|capitalizeCapitalize first letter
titlepost.title|titleConvert to title case
trimpost.title|trimRemove whitespace or characters
truncatepost.excerpt|truncate(100)Limit string length
excerptpost.content|excerpt(25)Trim to word count
excerpt_charspost.content|excerpt_chars(200)Trim to character count
striptagspost.content|striptagsRemove HTML tags
nl2brpost.content|nl2brNewlines to <br>
spacelesshtml|spacelessRemove whitespace between tags
pretagspost.content|pretagsEscape HTML inside <pre>
replacepost.title|replace('old', 'new')Replace text
split'a,b,c'|split(',')Split into array
slugpost.title|slugURL-friendly slug
sanitizepost.title|sanitizeAlias for slug
format'%s has %d posts'|format(user.name, count)sprintf-style formatting
url_encodequery|url_encodeURL encode
relativepost.link|relativeAbsolute URL to relative

Number

FilterExampleDescription
number_format1234.5|number_format(2)Format with decimals and separators
number_i18n1234|number_i18nFormat using WordPress localization
abs-5|absAbsolute value
round4.567|round(1)Round number

Date

FilterExampleDescription
datepost.date|date('F j, Y')Format date
date_i18npost.timestamp|date_i18n('F j, Y')Format with WordPress localization
date_modifypost.date|date_modify('+1 day')Modify date
time_agopost.date|time_agoHuman-readable time difference

Array

FilterExampleDescription
firstposts|firstFirst element
lastposts|lastLast element
joinnames|join(', ')Join into string
listnames|listHuman-readable list (A, B and C)
lengthposts|lengthCount elements
keysdata|keysGet keys
valuesdata|valuesGet values
sliceposts|slice(0, 3)Extract portion
batchitems|batch(3)Group into batches
columnusers|column('name')Extract column
mergecategories|merge(tags)Merge arrays
reverseposts|reverseReverse order
shuffleposts|shuffleRandomize order
sortitems|sortSort
filterposts|filter(p => p.featured)Keep matching elements
mapposts|map(p => p.title)Transform each element
reduceitems|reduce((a, b) => a + b, 0)Reduce to single value
findposts|find(p => p.featured)Find first match
arrayvalue|arrayEnsure value is array
wp_list_filterposts|wp_list_filter({status: 'publish'})Filter using wp_list_filter()

WordPress

FilterExampleDescription
wpautoppost.content|wpautopAdd paragraph tags
wptexturizepost.title|wptexturizeSmart quotes and dashes
shortcodespost.content|shortcodesProcess shortcodes
stripshortcodespost.content|stripshortcodesRemove shortcodes
antispambotuser.user_email|antispambotObfuscate email
kses_postpost.meta('html_field')|kses_postOutput HTML (overrides default escaping)

Utility

FilterExampleDescription
defaultpost.subtitle|default('No subtitle')Fallback if empty
json_encodedata|json_encodeEncode as JSON

Intl

Requires the PHP intl extension.

FilterExampleDescription
country_name'US'|country_nameCountry name from code
currency_name'USD'|currency_nameCurrency name from code
currency_symbol'EUR'|currency_symbolCurrency symbol from code
language_name'fr'|language_nameLanguage name from code
locale_name'en_US'|locale_nameLocale name from code
timezone_name'Europe/Paris'|timezone_nameTimezone name from identifier
format_currencyprice|format_currency('USD')Format as currency
format_number0.75|format_number('percent')Format number
format_datepost.date|format_date('long')Localized date
format_timepost.date|format_time('short')Localized time
format_datetimepost.date|format_datetimeLocalized date and time

WooCommerce

Requires WooCommerce.

FilterExampleDescription
currencyproduct.price|currencyFormat as store currency via wc_price()