ACF format_value Hook: Format Field Output [Guide]

ACF format_value() hook illustration: sliders for formatting settings

A field can store a plain number, but your site needs to show $19.00. The ACF format_value filter changes how a value is displayed without touching the stored data.

This guide covers the four arguments, the escaping flag, and a price formatting example.

Usage

<?php
add_filter( 'acf/format_value', 'my_format_value', 10, 4 );

function my_format_value( $value, $post_id, $field, $escape_html ) {
    return $value;
}

The arguments are:

  • $value is the formatted value, after ACF’s own formatting.
  • $post_id is the object the value belongs to.
  • $field is the field settings array.
  • $escape_html is true when ACF escapes the output, so you know whether markup will be shown as text.

Format a Price Field

This example adds a currency sign and two decimal places to a field named price:

<?php
add_filter( 'acf/format_value/name=price', 'my_format_price', 10, 3 );

function my_format_price( $value, $post_id, $field ) {
    if ( '' === $value ) {
        return $value;
    }

    return '$' . number_format( (float) $value, 2 );
}

The name=price variant limits the filter to that one field.

Escaping and Formatting Order

ACF runs format_value after its own formatting and before the result is cached and returned. Keep two things in mind:

  • Escape your output. If the value comes from user input, escape it with esc_html() before you return it.
  • Respect the flag. Check $escape_html before you add HTML tags. Markup returned to an escaped field shows up as raw tags.

Tip: format_value affects every get_field() call with formatting on. Use get_field( 'price', false, false ) when you need the raw number for calculations.

FAQs About ACF format_value

What Is the Difference Between format_value and load_value?

load_value changes the raw value ACF reads from the database. format_value changes the formatted result your template receives.

Does format_value Change the Stored Value?

No. The database keeps the original value. The filter changes only the output for that request.

How Do I Get the Unformatted Value?

Pass false as the third argument of get_field(), such as get_field( 'price', false, false ).

Conclusion

Use acf/format_value to control how values look on the page, and keep the stored data as it is. Pair it with get_field() and the unformatted flag when you need raw numbers 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.