December 6, 2016: Removed "not_equal" from the list of conditions. Props to Brad Nance!
Did you know that Gravity Forms provides a handy shortcode that allows you to display different content depending the data the user has entered in their submission? It’s a bit of a hidden gem.
How does it work? The shortcode allows you to create a condition (based on user input) that will evaluate to true or false. If the condition is true, the content within the shortcode will be displayed. If it is false, the content will not be displayed.
Gravity Forms’ conditional shortcode can be used anywhere WordPress shortcodes are supported. In the WordPress Classic Editor, you’ll have to decide where to slot in shortcodes yourself; if you’re using WordPress 5 or later you can simply drag in a shortcode block widget to wherever it looks best on the page you’re editing.
Here’s a list of the most useful locations:
- Notifications
- Confirmations
- HTML Fields
with the Gravity Forms Preview Submission perk - WordPress Post Content
with Gravity Forms Post Content Merge Tags perk - Post Content Template and Post Title Content Template
available via the Post Title and Post Body field settings respectively, more info
Quick Example
You have a few products that users can request additional information about. The user selects the product they’d like to learn more about using radio buttons on a simple Gravity Forms form.
You can use conditional shortcodes on the default confirmation to display a bit of information about the selected product.
This is what the above confirmation would generate if “Gravity Perks” was selected.
Usage Instructions
Let’s have a look at the different parameters that are available to the conditional shortcode. You can copy and paste the template Gravity Forms shortcode below. Fill in the values for each parameter as needed.
[gravityforms action="conditional" merge_tag="" condition="" value=""]
Content you would like to conditionally display.
[/gravityforms]
Parameters
action (string) (required)
The action that will be performed. Use
conditional
for conditional shortcodes.merge_tag (string) (required)
Specify the merge tag to be evaluated by the condition and the value.
You can find a full list of form-specific merge tags while editing a notification or confirmation to the right of the content editor. It looks like this:
condition (string) (required)
Enter the condition to be used to test the content of the merge tag with the value you specify. Possible conditions include:
- isnot
- is
- greater_than
- less_than
- contains
- starts_with
- ends_with
value (string) (required)
The value that will be compared against the merge_tag based on the condition.
The final “parameter” is the content. This is represented by any text you include inside the opening [gravityforms]
and closing [/gravityforms]
form shortcode tags. This text can include almost anything; from HTML to Gravity Forms merge tags.
Examples
Show Content Only if Value Exists
[gravityforms action="conditional" merge_tag="{My Field:1}" condition="isnot" value=""]
My Field Label: {My Field:1}
[/gravityforms]
Display User-requested Information
[gravityforms action="conditional" merge_tag="{More information on Gravity Perks:1}" condition="is" value="Gravity Perks"]
<a href="http://gravityperks.com">Take your forms to another universe with Gravity Perks!</a>
[/gravityforms]
If you are using multiple conditional shortcodes, you may notice some spacing issues when unmet conditionals display nothing. You can fix these issues with one of two methods.
- Collapse the shortcodes down so that there is no whitespace between shortcodes.
- Select “Disable Auto-formatting” (when available) and wrap everything in tags.
Nested Conditional Shortcodes
Conditional shortcodes can be nested to achieve more complex logic. Nesting the shortcodes requires using both the plural [gravityforms]
and singular [gravityform]
shortcode to function. For example:
[gravityforms action="conditional" merge_tag="{:3}" condition="greater_than" value="10"]
[gravityform action="conditional" merge_tag="{:3}" condition="less_than" value="30"]
Your value is greater than 10 less than 30
[/gravityform]
[/gravityforms]
Taking It Further
Preview Submission
With Gravity Forms Preview Submission, conditional shortcodes can be used within HTML fields on your form. Typically, Preview Submission is used to display merge tag values in your form, but it also adds support for conditional shortcodes.
This perk also adds support for inserting entry-based merge tags in a field’s “Default Value” setting. This perk can also be used to populate data entered on previous pages of the form to latter pages of the form, meaning that you could display conditional shortcode data at a later stage in the form submission process.
Post Content Merge Tags
Using Gravity Forms Post Content Merge Tags, conditional merge tags can be used in WordPress post content. Not only can you display merge tag values in the content, you can also show content on confirmation pages based on user-submitted values.
The upshot of this is that you can create personalized submission pages that maintain consistent styling across your WordPress website but are populated with data from users’ form submissions. This also allows you to implement persistent confirmation pages, meaning users can be sent an email with the confirmation page URL which they can save for future reference.
Both Preview Submission and Post Content Merge Tags are part of Gravity Perks, a suite of WordPress plugins that dramatically extend the functionality of Gravity Forms in all kinds of wonderful ways.

Advanced Conditional Shortcodes
One limitation of the default conditional shortcode is that it only allows for a single condition to control what is displayed. If you want to display content based on the values from multiple form fields, you need an alternative solution. That’s why we built a simple Gravity Forms plugin to add support for multiple conditions in a single solution.
Using the plugin, you can display content based on multiple conditions – for example, a user looking for information on cars for sale might first select the vehicle type from a dropdown (SUV, pickup, etc), and then the specific model from a checkbox conditional on the first answer. The advanced Gravity Forms shortcode will then populate the confirmation message with the information specific to the specific combination in the user’s form submission. You can add on as many conditions as you can think of – it’s up to you!
More on Gravity Forms Shortcodes
Learn more about other types of Gravity Forms Shortcodes, parameters used for each, and how to get started using shortcodes through our comprehensive guide to Gravity Forms shortcodes.
How’d we do?
There are so many ways to use Gravity Forms’ conditional shortcodes. We’d love to hear how you are using them. Let us know in the comments below.
For more information, check out Gravity Forms’ documentation for conditional shortcodes.
Did this resource help you do something awesome with Gravity Forms?
Then you'll absolutely love Gravity Perks; a suite of 46+ essential add-ons for Gravity Forms with support you can count on.
I’m looking to see if this can be the solution we want to display data from a form in posts and articles.
We have a table of positions names like “President,” “name” and “email”
Can the plugin be used to show the Name and Email associated with the position?
Our objective is to tell our posters to use a shortcode like [gf1 “President” “name” “email”] that when equal to the supplied position (President), the shortcode would return the name of the person and their email from the GF entry? We’re using the basic version of GravityWiz now but having a clean way to return insertable info would make upgrading to the full license a no brainer. Hope you can help a sort of technical guy understand what this would look like. Might need to hire someone to do the first one or two so we can do the rest. Thanks
James,
We’ve already followed up via email. To display Entry data on a Post/Page I would suggest checking out Entry Blocks Perk.
Best,
Hello, I want a user – example: it is possible to use only English letters in the name field ؟!
Hi Navid,
I’m not really tracking your question very well. Can you provide more information on your request?
Best,
Hey thanks for this, Are you able to please help me with this? I currently have a form that users can choose to submit their address or not.
So in the notification emails, i currently have all the address merge tags added in (e.g. {Address (Street Address):276.1}, {Address (Address Line 2):276.2}, {Address (City):276.3}, {Address (State / Province):276.4}, {Address (ZIP / Postal Code):276.5}, {Address (Country):276.6})
But since I added in the comma’s, if they don’t add in their address, i just get a bunch of comma’s in the email and a large white space.
How/Can i make all them conditional so that if there is no address filled in, it removes the comma’s and blank space?
Hi Ben,
The shortcode below should work for you.
[gravityforms action="conditional" merge_tag="{:276.1}" condition="isnot" value=""] {:276.1}, [/gravityforms] [gravityforms action="conditional" merge_tag="{:276.2}" condition="isnot" value=""] {:276.2}, [/gravityforms] [gravityforms action="conditional" merge_tag="{:276.3}" condition="isnot" value=""] {:276.3}, [/gravityforms] [gravityforms action="conditional" merge_tag="{:276.4}" condition="isnot" value=""] {:276.4}, [/gravityforms] [gravityforms action="conditional" merge_tag="{:276.5}" condition="isnot" value=""] {:276.5}, [/gravityforms] [gravityforms action="conditional" merge_tag="{:276.6}" condition="isnot" value=""] {:276.6}, [/gravityforms]
I hope this helps.
Best,
can this be used in notification and gravityflow notification emails? Similar to Mailchimp Conditional Merge tags?
Thanks
Hi Danny,
This should work in Notifications but I’m not really sure about Gravity Forms Notifications emails. You can give it a try and see if it works or not. In case it doesn’t work you can get in touch via our support form so we can forward this to our developers as a feature request.
Best,
Hello, I’m wondering if this kind of thing exists for use inside of form fields at all?
I have two fields, Restaurant Address and Mailing Address. The mailing address already has a conditional statement attached (“is this field the same as the restaurant address?).
I have additional fields for each to indicate a suite or apartment #.
I have a final “mailing address + suite” field where I am using a live merge tags snippet to pull both values from both the original mailing address and the suite number field to concatenate the values.
However, if the mailing address is the same as the restaurant address, I want to instead pull the values from the restaurant address and its suite number. Is that possible?
I know you stated above that shortcodes don’t work in field descriptions/fields, but this is sort of what I’m getting at: (77/71 pertains to my mailing address fields, 72/70 pertains to the restaurant address fields)
[gravityforms action="conditional" merge_tag="{:77}" condition="isnot" value=""] {:77} {:71} [/gravityforms] [gravityforms action="conditional" merge_tag="{:77}" condition="is" value=""] {:72} {:70} [/gravityforms]
Thanks for any hints in advance!
Hi Amy,
This snippet wouldn’t work for your use case. If you have an active Gravity Perks License, you can get in touch with us via our support form with an export of your form and we would happy to dig into this further.
Best,
Hello!
I created a system where a hidden number field will count how many checkboxes are selected in the form. I want, in the confirmation section, to display a specific message if 2 or more checkboxes are selected (aka, the number in the count number field is 2 or more). To do this i used the following code (keep in mind gravity forms is in another language for me):
Global text, should appear every time
[gravityforms action="conditional" merge_tag="{Número de caixas tipo 1:8}" condition="greater_than" value=2] You have selected 2 or more checkboxes. [/gravityforms]
More global text
When i submit the form, regardless of the value of the number field, i always get the message: “Oops! We could not locate your form.” (equivalent in English) I used the merge_tag tool as described in this article to make sure i was selecting the correct number field. Does anyone know why this happens?
Thank you.
Hi Ricardo,
The shortcode you have is correct and should work if the ID of the number field is 8. That said, looking at the error message you’re getting, I’m guessing this is actually related to something else and not the shortcode you’re using. If you’re a Gravity Perks Subscriber, you can get in touch via our support form, so we dig into this further.
Best,
For anyone wondering, the GF Docs shows you that the conditional shortcode can check to see if a particular option was chosen from a checkbox field like this:
[gravityforms action="conditional" merge_tag="{Question:49:value}" condition="contains" value="A"] — This Text to show — [/gravityforms]
But if you want to check to see if the user didn’t choose ANY options, it is as simple as changing condition=”is” and value=””.
I had to find it by trial and error, hope this helps someone
Hi this is great! I’ve been using GF for ages and I didn’t know this was possible.
May I ask if I wanted to only display the field if it was selected Would it be possible to display the field selection in a more eye-friendly manner? I.e I have entered the conditional merge tag as follows for a radial button field
[gravityforms action="conditional" merge_tag="{Buffet canape menu:91}" condition="isnot" Value=""]Buffet canape menu:{:91}[/gravityforms]
This then outputs the as ” Buffet canape menu:Modern Classics ” in the notification.
Would there be a way I could change this to something like (text within quotation marks being generated via the merge tag): thank you for enquiring about catering for a “Canape buffet” the “modern classics” menu is a great choice.
I’d be really grateful if you wouldn’t mind helping me make my notifications look a bit less robot like.
Thanks
Ben
Also I am using GW conditional pricing to adjust my product price based on the volume of a product ordered.
I tried to use the following code to stop the merge take showing should the product not have a price:
[gravityforms action="conditional" merge_tag="{Creates and slates canapes signature (Price):96.2}" condition="isnot" Value="0.00"]Creates and slates canapes signature (Price){:96.2}[/gravityforms]
I assume that I have got the “value” of “0.00” wrong? do I need to include the £ symbol?
Thanks
Ben
Can this be made to work in form field descriptions? I’m attempting to make this work in descriptions for correct pronoun use based on gender, such as “he” if the user selected “Male” in a previous dropdown field, and “she” if they selected “Female.” However, the shortcode is not being parsed and I’m certain I’ve typed the merge tag corrected. (FWIW, I do not have the menu to select merge tags available to me in this form field description box, and for those form inputs that I do have that option, merge tags for individual fields do not show anyway.)
Shortcodes are not parsed in field descriptions. You might consider taking Populate Anything for a spin which has support for Live Merge Tags. These merge tags can be used in field descriptions and will update automatically whenever their corresponding field changes.
Is there an short-code that will hide text if the condition is met rather than show it?
Not exactly but if you reverse the logic of your condition you can use the existing shortcode.
Is it possible to use multiple values separated by a comma in the “contains” logic?
[gravityforms action="conditional" merge_tag="{Country:5}" condition="is" value="United States,Canada,Australia,Benin"]
Hi Aaron, this is not supported but the our Advanced Conditional Shortcodes snippet will make create multiple conditions a lot easier.