How to Process Smart Tags in HTML Fields

Overview

Would you like to know how to process Smart Tags in the HTML form fields of your form? With a bit of PHP you can easily achieve this. This tutorial will show you how to use Smart Tags inside HTML fields.

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 an HTML block on your form.

However, this functionality may be useful if, for example, you’d like to pull the name of a logged-in user, display their website URL or even to display other details using custom Smart Tags.

Setup

To be able to use Smart Tags here, you can begin by copying the code shown below into your site.

This will not work for Smart Tags that pull user input values (for example, {field_id=”3″}).

/**
 * Run smart tags on HTML field content.
 *
 * @link   https://wpforms.com/developers/how-to-process-smart-tags-in-html-fields/
 *
 * @param  array $properties
 * @param  array $field
 * @param  array $form_data
 * @return array
 */
function wpf_dev_html_process_smarttags( $properties, $field, $form_data ) {
	$properties['inputs']['primary']['code'] = apply_filters( 'wpforms_process_smart_tags', $properties['inputs']['primary']['code'], $form_data );
	return $properties;
}
add_filter( 'wpforms_field_properties_html', 'wpf_dev_html_process_smarttags', 10, 3 );

Once you add that code snippet to your site, you can now set up some Smart Tags in the HTML field such as giving the user a personalized message based on their logged-in username.

add the smart tag to the HTML form field

And that’s it! You’re now able to process Smart Tags inside the HTML fields. Would you like to be able to do the same inside Checkbox field labels? Try out our tutorial on How to Process Smart Tags in Checkbox Labels.