Skip to main content

WordPress Filters

Filters specific to WordPress content processing.

post.content has already gone through WordPress's the_content filters, as in Timber: paragraphs added, shortcodes run. wpautop, shortcodes and stripshortcodes are for custom fields, or for the raw post.post_content.

wpautop and shortcodes output HTML. A text value is escaped before wpautop, so its own tags stay text; shortcodes cleans its input with wp_kses_post() first.

Content Processing​

FilterArgumentsDescription
wpautopbrAdd paragraph tags
wptexturize—Apply smart quotes and dashes
shortcodes—Process shortcodes
stripshortcodes—Remove shortcodes
antispambothex_encodingObfuscate email address
kses_post—Output HTML (overrides default escaping)

wpautop​

Converts double line breaks to paragraph tags.

Arguments:

  • br — Convert single line breaks to <br> (default: true)
{{ post.meta('bio')|wpautop }}                 <!-- A multi-line text field as paragraphs -->
{{ post.meta('bio')|wpautop(false) }} <!-- No <br> tags -->

wptexturize​

Applies typographic replacements (smart quotes, em dashes, etc.).

{{ post.title|wptexturize }}
{{ "He said \"Hello\" -- it's nice"|wptexturize }}

shortcodes​

Processes WordPress shortcodes in content.

{{ post.meta('promo')|shortcodes }}

stripshortcodes​

Removes WordPress shortcodes from content.

{{ post.meta('promo')|stripshortcodes }}

antispambot​

Obfuscates email addresses to prevent harvesting.

Arguments:

  • hex_encoding — Use hex encoding (default: 0)
{{ user.user_email|antispambot }}
{{ user.user_email|antispambot(1) }} <!-- Hex encoding -->

Common Patterns​

Clean excerpt without shortcodes​

{{ post.post_content|stripshortcodes|striptags|excerpt(25) }}
<a href="mailto:{{ user.user_email|antispambot }}">Contact</a>

Users' email is private: open it in Settings > Privacy to show another user's. A visitor always reads their own.

Safe HTML from custom fields​

{{ post.meta('html_field')|kses_post }}