ACF the_field() Function: Display Values [Guide]

ACF the_field() function illustration: eye icon for displaying a field

You have the value, and now it needs to appear on the page. The ACF the_field() function prints a field’s value straight into your template, so you don’t need an echo around get_field().

This guide covers its parameters, the formatting flag, and how it escapes output. To return the value instead of printing it, read the get_field guide.

Function Syntax

<?php
the_field( $selector, $post_id, $format_value );
  • $selector is the field name or field key.
  • $post_id is optional and defaults to the current post. It accepts the same formats as get_field(), such as 'user_5' or 'options'.
  • $format_value is optional and defaults to true. Set it to false to print the raw stored value.

Display a Field in a Template

Call it inside the loop, or anywhere the current post is set:

<?php
the_field( 'subtitle' );

To print a wrapper only when the field has a value, check it first with get_field():

<?php
$subtitle = get_field( 'subtitle' );

if ( $subtitle ) {
    echo '<p class="subtitle">' . esc_html( $subtitle ) . '</p>';
}

Display Values From Other Objects

Pass the object as the second argument to print a value from a user, a term, or the options page:

<?php
the_field( 'company_name', 'options' );

the_field( 'bio', 'user_5' );

Formatting and Escaping

Two settings affect the output:

  • Formatting. With $format_value set to true, ACF applies the field’s format settings, such as a date format or a select label. Set it to false to print the stored value.
  • Escaping. By default, the output is escaped, so HTML tags print as text. To print markup from a WYSIWYG field, enable the acf/the_field/allow_unsafe_html filter, and only for content you trust.

FAQs About ACF the_field()

What Is the Difference Between the_field() and get_field()?

the_field() prints the value, and get_field() returns it. Use get_field() when you need to compare or change the value before output.

Does the_field() Return Anything?

No. It echoes the value and returns nothing, so you can’t assign its result to a variable. Use get_field() for that.

Why Does the_field() Show HTML as Text?

ACF escapes the output by default. Use get_field() with your own escaping, or enable acf/the_field/allow_unsafe_html for trusted content.

Conclusion

the_field() is the shortest way to print an ACF value in a theme. Keep its escaping in mind, and use get_field() whenever you need the value in code.

Related ACF guides:

Need a custom theme or ACF setup? Hire a WordPress developer, or reach out to me directly.

About The Author

Picture of Andriy Haydash

Andriy Haydash

Andriy Haydash is a WordPress Expert who helps people build and launch successful WordPress membership and e-learning websites.

Note: Not all of the articles are written directly by me.
Affiliate Disclaimer: Some links in the post may be my affiliate links

Kinsta - Managed Hosting for WordPress

Before YOU Leave...
Join My Newsletter

Get practical tips & tricks on how to start, grow and market your course/membership site.