Template Variables

  • JNext lesson
  • KPrevious lesson
  • FSearch lessons
  • EscClear search

Core Forms supports two kinds of dynamic content: template tags (double curly braces) for use in form markup, and data variables (square brackets) for use in emails, messages, and redirect URLs.

Template Tags

Template tags use the {{namespace.property}} syntax and are processed when the form is rendered. They are replaced with dynamic values before the form is shown to the user.

User Tags

Access properties of the currently logged-in WordPress user:

<input type="hidden" name="user_email" value="{{user.user_email}}" />
<input type="hidden" name="user_name" value="{{user.display_name}}" />
<input type="text" name="name" value="{{user.first_name}}" placeholder="Your name" />

Any property of the WP_User object is available. Common ones:

  • {{user.user_email}} – Email address
  • {{user.display_name}} – Display name
  • {{user.first_name}} – First name
  • {{user.last_name}} – Last name
  • {{user.user_login}} – Username
  • {{user.ID}} – User ID

If the user is not logged in, user tags resolve to empty strings.

Post Tags

Access properties of the current WordPress post or page:

<input type="hidden" name="page_id" value="{{post.ID}}" />
<input type="hidden" name="page_title" value="{{post.post_title}}" />

Any property of the WP_Post object is available. Common ones:

  • {{post.ID}} – Post ID
  • {{post.post_title}} – Post title
  • {{post.post_name}} – Post slug
  • {{post.post_type}} – Post type

Post tags resolve to empty strings if there is no current post (e.g., on archive pages).

URL Parameter Tags

Access query string parameters from the current URL:

<input type="hidden" name="referral" value="{{url_params.ref}}" />
<input type="hidden" name="campaign" value="{{url_params.utm_campaign}}" />

If the page URL is example.com/contact/?ref=google&utm_campaign=spring, then:

  • {{url_params.ref}} resolves to “google”
  • {{url_params.utm_campaign}} resolves to “spring”

Fallback Values

You can provide a fallback value using the || syntax:

<input type="text" name="name" value="{{user.first_name||Visitor}}" />

If user.first_name is empty (e.g., user is not logged in), the value will be “Visitor”.

Registering Custom Tags

Use the cf_template_tags filter to add your own tag namespaces:

add_filter( 'cf_template_tags', function( $tags ) {
    $tags['site'] = function( $param ) {
        switch ( $param ) {
            case 'name':
                return get_bloginfo( 'name' );
            case 'url':
                return home_url();
            default:
                return '';
        }
    };
    return $tags;
} );

This registers {{site.name}} and {{site.url}} tags.

Data Variables

Data variables use the [variable_name] syntax and are processed after form submission. They are used in email notifications, auto-responders, redirect URLs, and webhook payloads to insert submitted field values.

Field Values

Use the field name in square brackets to insert its submitted value:

Dear [name],

Thank you for your message about [subject].
We will reply to [email] within 24 hours.

All Fields

Two special variables include all submitted fields at once:

  • [all] – All field values, one per line
  • [all:label] – All field values with their field names as labels

Example output of [all:label]:

Name: John Doe
Email: john@example.com
Message: I need help with my account.

System Variables

Built-in variables for submission metadata:

  • [CF_TIMESTAMP] – The date and time of submission
  • [CF_IP_ADDRESS] – The submitter’s IP address
  • [CF_USER_AGENT] – The submitter’s browser user agent string
  • [CF_REFERRER_URL] – The URL of the page where the form was submitted

Usage in Redirect URLs

Data variables work in redirect URLs, letting you pass submission data to the thank-you page:

https://example.com/thank-you/?name=[name]&email=[email]

Usage in Email Headers

Data variables also work in email headers:

Reply-To: [name] <[email]>
Cc: [manager_email]

Processing Order

Template tags ({{...}}) are processed during form rendering, before the user sees the form. Data variables ([...]) are processed after submission, when sending emails or building redirect URLs. These are two separate systems that work at different stages of the form lifecycle.