With a standard text field in Contact Form 7, you can set the default value like this:
[text first_name "Tessa"]
However, that value is static meaning it will always show the same value. With the Dynamic Text Extension plugin, we can use a shortcode for the default value of a dynamic text field so that the value changes with the user or page, like this:
[dynamictext first_name "CF7_get_current_user key='user_firstname'"]
In this case, we’ve used the included shortcode, CF7_get_current_user, which returns the user’s first name dynamically. However, we’ve eliminated the brackets and used only single quotes for attributes due to the syntax required for Contact Form 7 (DTX acts as an intermediary to process the shortcode properly even without its brackets).
Shortcode Syntax using Dynamic Text Extension
When using a shortcode as the Dynamic Value, you must:
- Remove the square brackets
[and] - Convert all double quotes
"to single quotes'
These two changes are required to avoid syntax errors within Contact Form 7.
So, this shortcode:
[shortcode attribute="value"]
becomes
shortcode attribute='value'
when placed inside a dynamic form field tags, e.g.,
[dynamictext input_name "shortcode attribute='value'"]
Included Shortcodes
The Contact Form 7 – Dynamic Text Extension includes some shortcodes out-of-the-box to make it easy to get started with the most common use cases. See below for all shortcodes that are included with this plugin including how to use them, attributes, and examples.
- Get the Current URL
- Get the Referring URL
- Page/Post Variables
- Post Meta & Custom Fields
- Get Featured Images or Attachments from Media Library
- Current User & User Meta
- Site/Blog Information
- HTTP GET Variables
- HTTP POST Variables
- Generate a random GUID
Custom Shortcodes
The Contact Form 7 Dynamic Text Extension has many shortcodes included but the possibilities are endless when you can use the DTX framework to write your very own custom shortcode.
Third-Party Shortcodes
Third-party shortcodes are any shortcodes provided by your WordPress theme or another plugin. As long as these shortcodes return a string or numeric value that can be displayed in a form field input, you can use them with the Contact Form 7 – Dynamic Text Extension plugin.