How to Process Smart Tags in Field Descriptions

Overview

Would you like to process Smart Tags in the form field description area of your form? With a bit of PHP, we can easily achieve this. In this tutorial, we’re going to show you how to use Smart Tags in the form field descriptions.

Smart Tags are a useful tool to dynamically pull and display specific data within your form.

By default, Smart Tags will not be processed if placed within any field descriptions on your form.

However, this functionality may be useful if, for example, you’d like to show today’s date, add the site admin email or even to display other details using custom Smart Tags.

Setup

First, open your form builder and in the Description field, enter the Smart Tag you wish to use.

For the purpose of this tutorial, we’ll add the {admin_email} Smart Tag to our form that will show in a contact area just below the form signature form field.

Add a Smart Tag to your form field's Description section

Next, copy the code shown below into your site.

Specific Form ID

In the code shown below, we’re only targeting the form ID 365. You’ll need to update the form ID number with your form ID.

/**
 * Run smart tags on all field descriptions.
 *
 * @link   https://wpforms.com/developers/how-to-process-smart-tags-in-field-descriptions/
 *
 * @param  array $properties
 * @param  array $field
 * @param  array $form_data
 */
 
function wpf_dev_field_properties_process_smarttags( $properties, $field, $form_data ) {
	if( 365 != $form_data[ 'id' ] ) 
    return;
	$properties['description'] = apply_filters( 'wpforms_process_smart_tags',       $properties['description'], $form_data );
	return $properties;
}
add_filter( 'wpforms_field_properties', 'wpf_dev_field_properties_process_smarttags', 10, 3 );

Once you add that code snippet to your site, you can now set up some Smart Tags in the field description.

Now the Smart Tag will show in the description area of the form

All WPForms

The code shown below would allow this on all your WPForms.

/**
 * Run smart tags on all field descriptions.
 *
 * @link   https://wpforms.com/developers/how-to-process-smart-tags-in-field-descriptions/
 *
 * @param  array $properties
 * @param  array $field
 * @param  array $form_data
 */
 
function wpf_dev_field_properties_process_smarttags( $properties, $field, $form_data ) {
	$properties['description'] = apply_filters( 'wpforms_process_smart_tags',       $properties['description'], $form_data );
	return $properties;
}
add_filter( 'wpforms_field_properties', 'wpf_dev_field_properties_process_smarttags', 10, 3 );

Note: The code snippet above will not work for Smart Tags that pull user input values (for example, {field_id="3"}).

And that’s all you need in order to process Smart Tags in your field descriptions! Would you like to learn how to create a custom Smart Tag? Take a look at our tutorial on How to Create a Custom Smart Tag.