gform_text_counter_template

Description

The gform_text_counter_template filter allows developers to modify the text counter template string. Use this filter to change the format of the text counter displayed below. The template supports three variables: {current}, {max}, and {remaining}

Usage

add_filter( 'gform_text_counter_template', 'your_function_name', 10, 3 );

To target a specific form:

add_filter( 'gform_text_counter_template_5', 'your_function_name', 10, 3 );

To target a specific field on a specific form:

add_filter( 'gform_text_counter_template_5_3', 'your_function_name', 10, 3 );

Parameters

ParameterTypeDescription
$templatestringThe text counter template.
$form_idintThe ID of the current form.
$fieldGF_FieldThe current field object.

Template Variables

VariableDescription
{current}The current number of characters entered.
{max}The maximum number of characters allowed.
{remaining}The number of characters remaining.

Example

The following example customizes the text counter format for all forms.

add_filter( 'gform_text_counter_template', function( $template, $form_id, $field ) {
    return 'Characters: {current}. Remaining: {remaining}. Max: {max}.';
}, 10, 3 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Since

This filter was added in Gravity Forms 3.0.0

Source

gravityforms/includes/fields/class-gf-field-text.php