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.
Thanks for this article. It provides an insight. Another better way of presenting better notifications without touching a line of code would be using this Plugin: https://wordpress.org/plugins/wp-html-mail/ On the Wp-Repo. Magically everything just falls into place and the spacing issue is solved almost automatically Thanks
Does this conditional shortcode work in all areas where merge tags work? for example, the Query Strings area under Redirect Confirmations?
Hi, Darren. No, I do not believe they are supported there.
Anyone know why I don’t see this Perk (GF Conditional Shortcodes) listed on the Install Perks page?
Hi Erik, this is not part of a Gravity Perks but rather a core Gravity Forms feature. If you have GF, you’re good to go. :)
ok, thanks. I purchased a license because I thought I need it. I don’t understand why my form is not showing the content based on the Value of the checkbox. David, I sent a Support request too about this. If you respond to that, can I give you WP access to look at it on a Staging Site?
We have the latest stable (2.2.5.14) version of GravityForms installed and we cannot seem to get the conditions “is” and “contains” to work. “isnot” works fine and shows content, but the other two do not on several fields. Am I overlooking something or is this a bug?
Many thanks for your help!
Hi Sandra, I’d ping Gravity Forms support for this one.
FYI, you state at the top that “December 6, 2016: Removed “not_equal” from the list of conditions. Props to Brad Nance!” and you did remove it from the list of conditions but did NOT remove it from the example code:
Wow, Matt. Just seeing this… And I fell prey to my own mistake. Ouch! Removed.
Hi David,
As always, your tutorials are incredibly helpful! Thanks again for posting these.
I did notice one issue. It looks like the condition, “not_equal” no longer works. It seems to be been replaced by “isnot”.
You might check this for yourself to see what results you get.
Thanks!
You are correct, Brad. Thanks for pointing this out. Article has been updated. :)
Was there ever a solution to the empty fields when using merge_tags to display neat and orderly without various line breaks throughout conformations?
Hi, I would like to ask for some help with gravity forms. I would like to use a value from field Total for my paypal button. The problem is that the value looks like this now: “100,00 €” and I need it in this format: “100.00”
Only way I was able to come up with is to use conditional logic like this:
[gravityforms action="conditional" merge_tag="{Price:1}" condition="is" value="100,00 €"] 100.00 [/gravityforms]
And so on for every price option. This is very complicated and prone to make mistakes.
Is there some simple way how to transform value from field Total to number that looks like this “100.00”?
Thanks for any help.
I do not know of a way to do this easily. It’s definitely something I can see being useful. :)
I agree with Jiri. It would be nice to make conditional shortcode work with prices. If I did not make any mistake, I can’t use the condtion “greater_than” with prices by example. Request for Gravity Forms :)
Not sure if this is the right place to ask this, but working with conditional logic on some “list” type fields, but can not figure out how to target specific values in a particular column. Say, if I have a first list field called “Site Data” and two input areas of that list are “No. of Months” and “No. of Visitors”, then my merge tag looks like this: {Site Data:1:}, but it targets both “columns” and outputs them in a table format. How can I read value from “No. of Months” separately?
Thank you in advance for any help.
hello, Awesome blog, just discoved it yesterday, asking google about gravity tricks. the webdesign is really slick and efficient, i love it :)
hi have a question for you wizzard :)
is it possible to gave multiple condition that make appear an item (thanks to the shortcode) on confirmation page. i mean :
this is the shortcode that i try to build, and testing, it does not work
[content removed]
i’ve only assigned A or B as a value in the form builder am i totaly wrong ? do you suggest another method for making this happen ? thanks for support
basically, what i try to do is this :
question 1 : -yes (value A) -no (value B) -i don’t know (value B)
question 2 : -yes (value A) -no (value B) -i don’t know (value B)
question 3 : -yes (value A) -no (value B) -i don’t know (value B)
on the confirmation message, i show a notation based on answers given during the survey
this
AAA 5 AAB 4 ABB 3 BBB 2 BBA 3 BAA 4
ABA 4 BAB 3
:)
Hi Sébastien, no, it does not let you add multiple conditions to a single shortcode. You would need to nest them using a bit of hack. Use [gravityform action="conditional"] for one condition and then [gravityforms action="conditional"] (plural) for the nested condition.
Thanks David, for the Answer. By nest, do you mean : Inside ? my english is limited. Thanks a lot anyway, ther’s a solution, You’re the wizard :)
Just to followup, it works now, i used anoyher technique, because, it seems that nested conditions are not allowed with shortcode (senn this on gravity forum, but not 100% sure..) i give each field it’s own value by a number (unique). Meaning option label a = value 1, option label b = value 2, option label g= 7 and so on.
Then, i add a number field to your form (admin visibilty only) and i enable calculation and use the merge tag drop down to insert my form fields to add them all up. This will produce a score. I can then use conditional logic based on this calculated number field to show/hide information either in the form via multiple HTML fields, or via multiple confirmations with conditions set to show based on this calculated number field. thanks for all
Hi The guys at GravityForms told me to use this conditional to test if the one of two options for a signature field where empty and display the one with something in it, and not display anything for the empty one. However, this does not show anything at all. Any clues?
Signed:
[gravityforms action="conditional" merge_tag="{Digital Signature (First):9.3} {Digital Signature (Last):9.6}" condition="isnot" value=""][/gravityforms] [gravityforms action="conditional" merge_tag="{Signature:8}" condition="isnot" value=""][/gravityforms]
Well it looks like the comment removed the HTML. Please bear with me while I experiment:
[gravityforms action="conditional" merge_tag="{Update another card?:54}" condition="is" value="Yes"]\<tr\>\<td\>{Lowes Petroleum BP+ Card Number:26}\</td\>\<td\>{Maintenance:27}\</td\>\<td\>{Services Required:30}\</td\>\<td\>{Prompted for at POS::42}\</td\>\<td\>{Additional Notes::33}\</td\>\</tr\>[/gravityforms]
Hi David,
The confirmation code is great!
I do have a problem with the conditional shortcode, though. It doesn’t show the relevant information. (The shortcode I am using is working OK in notification emails. Just not on the confirmation page.)
An example is:
[gravityforms action="conditional" merge_tag="{Update another card?:54}" condition="is" value="Yes"] {Card Number:26} {Maintenance:27} {Services Required:30} {Prompted for at POS::42} {Additional Notes::33} [/gravityforms]
If I remove the shortcode, the confirmation page shows the empty table rows, up to 9 of them, which looks a bit messy. It would be ideal to hide the empty rows.
I also tried running the lines together with no success, like so:
[gravityforms action="conditional" merge_tag="{Update another card?:54}" condition="is" value="Yes"]{Lowes Petroleum BP+ Card Number:26}{Maintenance:27}{Services Required:30}{Prompted for at POS::42}{Additional Notes::33}[/gravityforms]
Any thoughts on that would be terrific!
(It’s a login access only form, so I can’t just give you the URL.)
Thanks, Carolyn
Hi Carolyn, if it’s working in your Notifications but not your Confirmation, it might be a GF bug. I’d reach out to GF Support.
Thanks, David. I had that thought about 2 hours ago. It makes sense. :)
Carolyn
Hello,
I am unable to get my shortcodes to work as expected. Using the following code, where “aabbcc” and “xxyyzz” represents text, it seems to me that my “is” condition does not work. No matter whether the mergtag value is “people” or not, “aabbcc” gets sent in my notification. When i completely remove the “isnot” condition, then nothing gets sent at all. Do you know why this might be? Am i doing something wrong?
Thank you in advance of your assistance.
[gravityforms action="conditional" merge_tag="{roommatepref:24}" condition="isnot" value="people"] aabbcc [/gravityforms]
[gravityforms action="conditional" merge_tag="{roommatepref:24}" condition="is" value="people"] xxyyzz [/gravityforms]
Hi Katrina, it’s been a while since you posted, but feel free to send me an export of your form. Email david at gravitywiz dot com.
Hi there! Fantastic plugin, tutorials and snipplets — thank you! Having trouble with “nesting” the shortcode. Here is the example of syntax I’m using:
It’s not working. In my confirmation I see the actual text [/gravityforms] after my CS DT NEW text. What am I ding wrong?
Thanks in advance for your help!
Hey Mark… you’re right. The nested conditions don’t work as expected. I played around it with it and found a hack. GF used to use a [gravityform] (singular) shortcode before switching to the plural [gravityforms]. We can use that to our advantage here and nested a singular shortcode inside the plural. Example: http://pastie.org/private/qh1ootl6wninwqadsha
Fantastic solution! Works like a charm! Thank you David :-)
Hi David, Alex. I have a problem. I tried to nest the conditions, with two seem to work but with three no. Eg: [gravityforms action="conditional" merge_tag="{Field:value}" condition="is" value="x"][gravityform action="conditional" merge_tag="{Field:value}" condition="is" value="y"][gravityform action="conditional" merge_tag="{Field:value}" condition="is" value="z"]TEST[/gravityform][/gravityform][/gravityforms] It’s not work, I also tried with: [gravityforms action="conditional" merge_tag="{Field:value}" condition="is" value="x"][gravityform action="conditional" merge_tag="{Field:value}" condition="is" value="y"][gravityforms action="conditional" merge_tag="{Field:value}" condition="is" value="z"]TEST[/gravityforms][/gravityform][/gravityforms] but nothing Do you have any suggestions? Thanks in advance
Hi Mark, there’s a trick for this but I’d actually recommend just using our Advanced Conditional Shortcode here: https://gist.github.com/spivurno/9db18385ed1d1f11a897bdfa8a1f2007 It supports creating multiple conditions in a single shortcode so you don’t need to nest.
Thanks David,
Where do I have to put the file?
Thank you
Hi David, I did so. I put the file in the folder \wp-content/plugins/gravityforms After that I did so [gravityform action="conditional" relation="all" value="{field1:2}" operator="is" compare="value1" value="{field2:3}" operator="is" compare="value2" value="{field3:4}" operator="is" compare="value3"]TEST[/gravityform] Is it right? It isn’t work :(
Thanks Alex
Is there a way to have multiple conditions or between x and y?
Thanks so much!
Is there any option for AND/OR conditionals?
e.g.combined: IF (Field1 IS “A” ) OR (Field2 IS “A”) THEN { }
IF (Field1 IS “A” ) AND (Field2 IS “A”) THEN { }
Hi Matt, “OR” is not supported but you can do “AND” conditions by “nesting” the shortcode.
[if field1 is A] [if field2 is A] your content [/if] [/if]
Thanks for the complete reply. I was wondering if nested conditionals were allowed – we should be able to make it all work that way.
Thanks!
David.
Great article and it answers the question I came upon in the past couple of days. A client wanted to have a variable notification sent out from a form submission where the text varied based on choices that the visitor chose. To accomplish this, I need a Boolean AND function.
Above, you noted that this could be accomplished like this:
[if field1 is A] [if field2 is A] your content [/if] [/if]
However, I’m assuming that you actually mean what I’ve put in this PasteBin: http://pastebin.com/22KFMLZW
Is that correct, or should I actually be using an “IF” statement?
Thanks.
Hi James, what you have is correct. The “if” was just to demonstrate the concept. Sorry for the confusion. :)
Thanks David.
Looks like the nested ability no longer functions. Of course, I still could have goofed some code. I was nesting three consecutive sets so that may be why it doesn’t work either. LOL.
Thanks for the clarification though.
JDD
Hi James, I believe it will work if nested on two deep and alternating usage of [gravityforms] (plural) vs [gravityform] singluar.
I tried the two deep and alternating (may have goofed something), but finally came up with a solution that functions perfectly for my needs – albeit unconventional. I ticked the box for “Show Values” on the two determining fields and assigned them numbers. Then, I created an “Admin Only” number field and added the values from the two fields. I used that result i a single [gravityforms] shortcode and it actually worked flawlessly. I went back to some old school coding that I used to do to accomplish that one, but I’m happy to say it worked fantastically.
Thanks for all the knowledge you impart here David. :)
A quick question if you’re able to help:
I’m trying to set up conditional logic so that if the field’s result is:
Less than 10, display “x”. Else, More than 9 & less than 50, display “y”. Else, More than 49, display “z”.
I’m having trouble with that middle one that declares a range. There’s no “range” condition, and trying to wrap multiple greater_than and less_than conditionals together around a single piece of content seems to mess up other conditional statements that come after it.
Is there a way to do this? The only solution I see is to use the “is” conditional as a discrete statement and copy it for each possible value in the range. Yikes!
I think your best bet is to change the order of your conditions.
If less than 10: display x Else if more than 49: display z Else: display y
Hi David, Jordan. Thanks for this. Is the ability to include conditionals in the post content template a new ability that has crept into a recent update of Gravity Forms? I ask because in the past this wasn’t possible. Thanks.
Hi Richard, to be clear, the shortcode is not processed in the Post Content Template itself, but the merge tags are replaced and the shortcode is processed when viewing the post (post editor, post frontend).
Brilliant, a gem indeed! Thanks so much for the write-up.
Our pleasure, Piet. Glad you liked it.