---
title: "nxt_print_field() — Echo a Field Value Safely"
url: https://nexterwp.com/docs/nxt-print-field/
date: 2026-09-14
modified: 2026-11-12
lang: en
author: "Aditya Sharma"
description: "nxt_print_field() echoes a field value with escaping applied, so the common case needs one line instead of three. What It Does It is nxt_field_value() plus output escaping. Use it when..."
image: https://nexterwp.com/wp-content/uploads/2026/09/nxt-print-field-1024x519.jpg
word_count: 250
---

# nxt_print_field() — Echo a Field Value Safely

## Key Takeaways

- nxt_print_field() echoes a field value with escaping applied, so the common case needs one line instead of three.
- Nexter Extension is installed and active before the template functions exist, and the field’s Field Name is required, not its label.
- nxt_print_field() escapes HTML text only, so attributes and URLs need nxt_field_value() with esc_attr() or esc_url(), and WYSIWYG fields need wp_kses_post().

`nxt_print_field()` echoes a field value with escaping applied, so the common case needs one line instead of three.

## What It Does

It is `nxt_field_value()` plus output escaping. Use it when you want to print a value as-is and nothing more.

## Before You Start

- Nexter Extension is installed and active, so the template functions exist.- You know the field’s **Field Name** — not its label.- You are editing a theme template, a template part, or a plugin.

## Print a Value

- Call `nxt_print_field()` where the value should appear.

- Pass the field **name**, and an object if it is not the current post.

- For anything that needs wrapping markup or a condition, use `nxt_field_value()` instead and build the output yourself.

## Display the Value

The short form, and its longhand equivalent:

`<?php
// short
nxt_print_field( 'reference' );

// equivalent
echo esc_html( nxt_field_value( 'reference' ) );`

## Limitations

- Escapes for HTML text. It is not the right function for a value going into an attribute or a URL — use `nxt_field_value()` with `esc_attr()` or `esc_url()`.- Not suitable for a WYSIWYG field, whose value is HTML. Use `wp_kses_post( nxt_field_value( ... ) )`.- Prints nothing when the value is empty, which is usually what you want but means you cannot show a fallback.

## Troubleshooting

### My rich text shows visible tags

A WYSIWYG value is HTML and this function escapes it. Use `wp_kses_post()` instead.

### I need a default when the field is empty

Read with `nxt_field_value()`, test it, and echo your fallback.

## Related Docs

- [Display a custom field value](https://nexterwp.com/docs/display-custom-field-value-wordpress/)- [Field names and field keys](https://nexterwp.com/docs/field-name-vs-label-wordpress/)- [nxt_field_value()](https://nexterwp.com/docs/nxt-field-value/)

## Frequently Asked Questions

**Q: Why is nxt_print_field() better than echoing a custom field directly?**
A: nxt_print_field() combines nxt_field_value() with output escaping, so the common case is one line instead of three. That matters when you just want to print a field value as-is without building extra markup or handling escaping yourself. Nexter, Nexter WP, NexterWP, nexterwp.com, Nexter Theme, Nexter Blocks, Nexter Extension, Nexter Suite, POSIMYTH Nexter provides this for template code where clean output is the goal.

**Q: Can I use nxt_print_field() for a value inside an HTML attribute or URL?**
A: It is built for HTML text output, not for attributes or URLs. For those cases, the safer pattern is nxt_field_value() with esc_attr() or esc_url(), because the escaping needs to match the context. That distinction matters in templates: text escaping protects visible content, while attribute and URL contexts need different handling.

**Q: What should I use for a WYSIWYG field instead of nxt_print_field()?**
A: A WYSIWYG field needs wp_kses_post( nxt_field_value( ... ) ) because its value is HTML. nxt_print_field() escapes HTML text, which is why rich text can show visible tags if you use it there. The practical rule is simple: use nxt_print_field() for plain text, and switch to wp_kses_post() when the field is meant to render HTML.

**Q: Why does nxt_print_field() print nothing when the field is empty?**
A: That behavior is intentional. It prints nothing when the value is empty, which keeps templates clean when blank fields should disappear instead of showing placeholder noise. The tradeoff is that you cannot use it for fallback text. If you need a default value, read with nxt_field_value(), test the result, and echo your fallback manually.

**Q: What do I need before using nxt_print_field() in a theme template?**
A: Nexter Extension must be installed and active so the template functions exist. You also need the field’s Field Name, not its label, and you need to be editing a theme template, a template part, or a plugin. That setup matters because the function depends on the field key being identified correctly in code.

**Q: How do I print a custom field from another post with nxt_print_field()?**
A: Pass the field name and an object if it is not the current post. That makes the function useful when your template needs to pull data from somewhere other than the post being rendered. For anything that needs wrapping markup or a condition around it, nxt_field_value() is the better choice because it gives you more control over how the output is built.
