Nested Merge Tags
Since GravityWP – Advanced Merge Tags 1.2 it’s possible to use Nested Merge Tags (variables) inside your Advanced Merge Tag modifiers.
Currently supported in:
- Merge tags with search filters, like filter1=
- gwp_date_format
- gwp_date_updated
- gwp_date_created
- gwp_append
- gwp_replace
How to use nested Merge Tags?
When using Merge Tags inside Merge Tags or Modifiers, you have to change the curly brackets. For example when you want to use the value of this example Merge Tag:
{String:1}
You have to use it like this:
*|String:1|*
Example gwp_replace with Nested Merge Tags
For example: you have three Single Line Text fields in your Gravity Form.
- A string you want to replace part of (Field ID 1)
- The part you want replaced (search=) (Field ID 2)
- What you want to replace it with (replace=) (Field ID 3)
Without Nested variables this would look like this, where ‘WP’ would be replaced by ‘WordPress’:
{String:1:gwp_replace search='WP' replace='WordPress'}
When using Nested variables, where we use data from the entry itself to replace the text, it would look like this:
{String:1:gwp_replace search='*|Which part to replace:2|*' replace='*|Replace with:3|*'}
Try it out
Frequently Asked Questions
Yes! With Nested Merge Tags, you can dynamically insert one field’s value into another merge tag’s modifier. This allows you to create powerful, flexible forms especially when combining values for search, filters, or replacements. Instead of static input, nested merge tags adapt based on user input, making your merge tags smarter.
Example:
Let’s say you want to replace a part of a sentence entered by the user using values from other fields:{Original Sentence:1:gwp_replace search='*|Text to Find:3|*' replace='*|Replace With:4|*'}
If:
-Field 1 = “I love GravityWP”
-Field 3 = “love”
-Field 4 = “use”
The output will be:I use GravityWP
When merge tags are used inside modifier attributes (like search=, replace=, or value1=), regular {} brackets won’t work. GravityWP solves this with the *| |* syntax. This ensures the inner tags are evaluated first then inserted into the main merge tag.
Example:
Replace part of Field 1’s content dynamically:{Field:1:gwp_replace search='*|Field:3|*' replace='*|Field:4|*'}
As of version 1.2+, nested merge tags work inside several GravityWP modifiers, including:
-gwp_replace
-gwp_append
-gwp_date_created
-gwp_date_updated
-gwp_date_format
-All modifiers that support filters like filter1=, value1=
You can even use nested tags in conditions or date math.
Example with a date modifier:{gwp_now modify="*|Days to Add:5|* days" format="Y-m-d"}
Absolutely. You can display the output of a merge tag (with nested variables) in:
-HTML Fields
-Confirmation messages
-Notifications
Just make sure your merge tag syntax follows this format:{Field:ID:modifier param='*|AnotherField:ID|*'}
Example confirmation:Replaced Text: {1:gwp_replace search='*|3|*' replace='*|4|*'}
If the nested tag is not producing results, double-check these:
-You used *| |* instead of {} for the inner merge tag.
-All field IDs exist and are filled by the user before processing.
-The modifier you’re using supports nesting.
Incorrect:{Field:1:gwp_replace search='{Field:3}' replace='{Field:4}'}
Correct:{Field:1:gwp_replace search='*|Field:3|*' replace='*|Field:4|*'}
Last updated: 22-07-2025