# Word Limit for an ACF Text Area

> Shows an error when a text area or WYSIWYG field goes over a set number of words, which keeps summaries and teasers short.

- Type: PHP
- Runs: Run everywhere
- Category: [Custom Post Types & Fields](https://wpide.com/library/category/post-types/)
- Tags: acf, validation, word-count
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/acf-validate-word-limit/

## Code

```php
// Field name and maximum words.
$wpide_acf_words_field = 'summary';
$wpide_acf_words_max   = 60;

add_filter( 'acf/validate_value/name=' . $wpide_acf_words_field, function ( $valid, $value ) use ( $wpide_acf_words_max ) {
    if ( true !== $valid ) {
        return $valid;
    }

    $words = str_word_count( wp_strip_all_tags( (string) $value ) );

    if ( $words > $wpide_acf_words_max ) {
        return sprintf( 'Please keep this under %1$d words (currently %2$d).', $wpide_acf_words_max, $words );
    }

    return $valid;
}, 10, 2 );
```

## Notes

Set the field name and limit. ACF's own character limit counts characters, not words.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Word Limit for an ACF Text Area" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
