How to Process Smart Tags in HTML Fields


Would you like to process Smart Tags in HTML/Code Block 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. Inside WPForms there are many built-in Smart Tags already available for you to use as well as many tutorials and snippets on how to create your very own Smart Tags.

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.

Adding an HTML/Code Block field to your form

We’ll begin by creating a new form and adding an HTML/Code Block form field to our form. You can find this form field under the Fancy Fields while inside the form builder.

Add an HTML Code Block to your form

Inside this field, you can add your text and Smart Tags. For the purpose of this tutorial, we’ll just add the name of the logged-in user to this form field.

Hi {user_full_name}, complete the form below and if you have any questions, please feel free to reach out to your local consultant.

Add your text and Smart Tags to the HTML field

For any assistance in creating a form, please review this documentation.

Adding code to process the Smart Tags in the HTML

Now it’s time to add a small code snippet to your site that will allow you to use Smart Tags inside the HTML/Code Block form field. If you need any help on how to add code to your site, please review this tutorial.

 * Process Smart Tags inside HTML / Code Block form fields.
 * @link

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 );

This snippet cannot be used for Smart Tags that are used to display form field values such as {field_id=”#”}.

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.

once you have added the snippet to your site you can now process smart tags inside the html 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.

Filter References:

Q: Is there a limit to how many Smart Tags you can use?

A: There is no limit on how many Smart Tags you can use in the HTML / Code Block. If you aren’t seeing all of your Smart Tags in this area, be sure that these Smart Tags are created correctly.