Field values are content someone typed. Printing them unescaped is how a site ends up serving markup it did not intend. The right escaping function depends on where the value lands.
What It Does
WordPress has a different escaper for each context. Choosing by context, not by habit, is the whole discipline.
Before You Start
- Nexter Extension is active.
- A field group with values saved on a post.
- You know the field’s Field Name.
Pick the Right Escaper
- Plain text in the page body →
esc_html().

- A URL, in
hreforsrc→esc_url().
- Any other HTML attribute →
esc_attr().
- A WYSIWYG value, which is genuinely HTML →
wp_kses_post(). Neveresc_html(), which would print the tags.
- A textarea value that needs its line breaks →
nl2br( esc_html( ... ) ).
Display the Value
Each context, side by side:
<?php
// text
echo esc_html( nxt_field_value( 'reference' ) );
// url
printf( '<a href="%s">Visit</a>', esc_url( nxt_field_value( 'tour' ) ) );
// attribute
printf( '<div style="--accent:%s">', esc_attr( nxt_field_value( 'accent' ) ) );
// rich text
echo wp_kses_post( nxt_field_value( 'description' ) );
// multi-line plain text
echo nl2br( esc_html( nxt_field_value( 'summary' ) ) );
Limitations
nxt_print_field()escapes for HTML text only. It is the wrong function for an attribute, a URL or a WYSIWYG value.- Escaping is for output. It does not make a value safe to store, and it is not a substitute for the field’s own sanitisation on save.
Troubleshooting
My rich text shows <p> tags on the page
It is being escaped with esc_html(). Use wp_kses_post() for a WYSIWYG value.
A URL with an ampersand breaks the link
Use esc_url(), which encodes the URL properly. esc_html() does not.










