Using the [gvlogic] shortcode
The [gvlogic] shortcode shows or hides content depending on a value, such as a field in the entry, whether the visitor is signed in, or which screen of the View is open. It works in Custom Content fields and widgets in a View, and in Gravity Forms confirmations and notifications, where merge tags are filled with the submitted entry's values.
To hide a whole field in a View, Field Conditional Logic does it without a shortcode.
This example shows one message on closed tickets and another on the rest:
[gvlogic if="{Issue Status:13}" is="Closed"]
This ticket is closed. {Assigned Staff:49} worked on it.
[else]
This ticket is {Issue Status:13}. {Assigned Staff:49} is working on it.
[/gvlogic]
Comparison parameters #
The if parameter holds the value to test, usually a merge tag. Add one of these to say what to compare it with:
| Parameter | True when the if value |
|---|---|
is or equals | Is the same as the value you give |
isnot | Is different |
contains | Includes the value you give, with or without other text |
not_contains | Doesn't include it |
starts_with | Starts with it |
ends_with | Ends with it |
in | Matches at least one item in a comma-separated list |
not_in | Matches none of them |
greater_than | Is a higher number or a later date |
greater_than_or_is or greater_than_or_equals | Is higher or later, or the same |
less_than | Is a lower number or an earlier date |
less_than_or_is or less_than_or_equals | Is lower or earlier, or the same |
in and not_in split both values at each comma, so Smith, John counts as two items and John matches it. Use is or contains for text with commas of its own.
Checking for an empty value
Compare with an empty value to test whether a field has anything in it:
[gvlogic if="{Phone:54}" isnot=""]
Call {Phone:54}.
[else]
No phone number on file.
[/gvlogic]A shortcode with if and no comparison also tests for a value, but it treats 0, No and false as empty. Use isnot="" on a field that can hold those.
When an empty box still shows
The Hide empty fields setting hides a Custom Content field only when nothing is left after the shortcode runs. Spaces and line breaks around the shortcode are fine. Text or HTML outside it keeps the field visible, so put headings and labels inside it:
[gvlogic if="{Phone:54}" isnot=""]
<h4>Phone</h4>
{Phone:54}
[/gvlogic]Leave Automatically add paragraphs to content off in the field's settings, because with it on the field is never empty and the box stays. On the Multiple Entries screen of a Table View, every row keeps its cell, so the cell stays with nothing in it.
Showing something else when there's no match #
Put [else] inside the shortcode for the other case. [else if] takes the same parameters as [gvlogic], and the first match wins:
[gvlogic if="{Address (City):14.3}" is="New York"]
You live in New York City.
[else if="{Address (State):14.4}" is="New York"]
You live in New York State.
[else]
You live outside New York.
[/gvlogic]For a short one-line alternative, use the else parameter, which also accepts merge tags:
[gvlogic if="{Number:5}" is="28" else="{Number:5} is not the number."]
The number is 28.
[/gvlogic]Comparing choice fields #
Radio Buttons, Drop Down and Checkboxes fields hold a label and a value for each choice, and a merge tag prints the label. Comparing with the value keeps a condition working when someone rewords a label.
Radio Buttons and Drop Down fields
Turn on Show Values in the field's choices to give each choice its own value. Then add :value to the merge tag and compare with that value:
[gvlogic if="{Level:7:value}" is="level_a"]
Start with the beginner guide.
[else if="{Level:7:value}" is="level_b"]
Go straight to the advanced guide.
[/gvlogic]Without :value, the same comparison is never true, because {Level:7} prints the label.
These fields have no separate input for each choice. {Level:7.1} and {Level:7.2} both print the chosen label, so a test on either one is true for every entry with an answer.
Checkboxes fields
A Checkboxes field has one input per choice, and that changes how you compare.
To ask whether a choice is among those ticked, use the whole field with contains. The whole field prints every ticked label, separated by commas, so is matches only when that one choice is the only one ticked.
[gvlogic if="{Favorite foods:1}" contains="Pizza"]
Pizza is on the list.
[/gvlogic]To test one specific choice, use its input, {Field label:FIELD_ID.CHOICE_NUMBER}. A ticked choice prints its label, and an unticked one prints nothing:
[gvlogic if="{Favorite foods:1.2}" isnot=""]
You ticked the second choice.
[/gvlogic]This test keeps working if the label changes. With Show Values on, the input still prints the label, and {Favorite foods:1.2:value} prints the value.
To match any of several choices, use the whole field with in:
[gvlogic if="{Favorite foods:1}" in="Pizza,Pasta,Risotto"]
An Italian evening, then.
[/gvlogic]The numbers in .1 and .2 follow the order of the choices and skip multiples of ten, so the tenth choice is .11. Check your conditions after you reorder or delete a choice.
Showing content to signed-in users #
To check whether the visitor is signed in, compare {user:ID} with an empty value, because a visitor who isn't signed in has no user ID:
[gvlogic if="{user:ID}" isnot=""]
Welcome back.
[else]
Sign in to see your entries.
[/gvlogic]The logged_in parameter does the same on its own or next to another comparison. Use logged_in="true" for signed-in users and logged_in="false" for visitors:
[gvlogic if="{Number:5}" is="28" logged_in="true"]
The number is 28, and you're signed in.
[else]
Either the number isn't 28, or you aren't signed in.
[/gvlogic]Don't combine logged_in with ||, because a visitor can see the content when the last value matches. Put logged_in on an outer [gvlogic] and the || comparison on an inner [gvlogic2]:
[gvlogic logged_in="true"]
[gvlogic2 if="{Department:7}" is="Sales||Support"]
Welcome to the team area.
[/gvlogic2]
[/gvlogic]Checking a user's role #
[gvlogic] has no parameter for a user's role, and {user:roles} prints nothing, so the shortcode can't check the role of the person viewing the page. The right approach depends on whose role matters.
The role of the person viewing the page
To show a whole field to certain roles, open the field's settings in the View editor and go to Visibility. Tick Make visible only to logged-in users?, then choose a level in Make visible for, such as Editor Or Higher. Everyone below that level sees the View without the field, and in a Table View its column is left out. Restricting a View to logged-in users or user roles has the full list.
Field Conditional Logic, part of Advanced Filtering in GravityView Pro, checks exact roles instead:
- In the field's settings, under Visibility, click Add Condition.
- Choose Current User Role, keep
has ANY of, and pick the roles that should see the field.

- Click Close, then Update to save the View.
A condition on Editor leaves administrators out, which is the difference from Editor Or Higher. In this Table View example, Empty Field Content is blank, and the Internal notes column remains visible with empty cells for administrators and signed-out visitors.
To show part of a field by role, use the Members plugin, a free plugin that adds a [members_access] shortcode. It works in a Custom Content field, and on a page or post:
[members_access role="administrator,editor"]
Visible to administrators and editors.
[/members_access]
[members_access role="administrator,editor" operator="!"]
Visible to everyone else.
[/members_access]List the roles separated by commas. Add operator="!" to show the content to everyone without those roles, including visitors who aren't signed in.
The role of the person who created the entry
{created_by:roles} prints the roles of the user who created the entry, such as editor, or editor, author for a user with two. It is empty for an entry submitted while signed out, and it says nothing about who is viewing the page. Compare it with contains, because is matches only a user with exactly that one role:
[gvlogic if="{created_by:roles}" contains="administrator"]
Added by the site team.
[else]
Added by a member.
[/gvlogic]To filter the View itself by the creator's role, use the Created By User Role condition in the View's Advanced Filter setting. Showing only entries created by users with a certain role has the steps.
Comparing numbers and dates #
The greater_than and less_than parameters compare numbers and dates. Add :value to a Number field's merge tag, because a value printed with a thousands separator, such as 1,200, doesn't compare correctly:
[gvlogic if="{Number:5:value}" greater_than="12"]
More than twelve.
[else]
Twelve or fewer.
[/gvlogic]A value with a currency symbol, such as $1,200.00, doesn't compare correctly, even with :value.
Dates
Compare a Date field with a date written as year, month and day:
[gvlogic if="{Date:3}" is="2026-03-14"]
This event is on March 14, 2026.
[/gvlogic]On a Date field set to a day-first format, add :mdy to the merge tag, such as {Date:3:mdy}, or the day and month are read the wrong way round.
You can also compare two Date fields:
[gvlogic if="{Date:3}" greater_than="{Second Date:6}"]
The first date is later.
[else]
The first date isn't later.
[/gvlogic]If the two fields use different date formats, add the same date modifier to both, such as {Date:3:mdy}.
To compare with a relative date, write relative: before it, such as greater_than="relative:today" or greater_than="relative:-10 years". A bare today doesn't work.
To show or hide a whole field by date with no shortcode, add a Field Conditional Logic condition on the Date field. It has Today, Yesterday and Tomorrow as values. For a worked example, see Highlighting entries about to expire "today".
Showing content on one screen of the View #
Use if="context" to test which screen is open. The values are multiple for Multiple Entries, single for Single Entry, edit for Edit Entry, and singular for either of the last two:
[gvlogic if="context" is="multiple"]
Click a name to learn more.
[else]
You are viewing or editing one entry.
[/gvlogic]Combining values with || and && #
Separate values with || to match any of them, or with && to match all of them. Leave no spaces around these characters, because spaces count as part of the value.
[gvlogic if="{Email:16}" ends_with="@icloud.com||@me.com||@mac.com"]
Your email address is from Apple.
[else if="{Email:16}" ends_with="@gmail.com||@googlemail.com"]
Your email address is from Google.
[else]
Your email address is from another provider.
[/gvlogic][gvlogic if="{Skills:38}" contains="Google Docs&&Photoshop&&Excel"]
The applicant mentioned all three.
[else]
The applicant left at least one out.
[/gvlogic]Merge tags work on both sides:
[gvlogic if="{Score:5:value}" greater_than="{Try 1:8:value}||{Try 2:9:value}"]
{Score:5} beats at least one of your earlier tries.
[/gvlogic]With isnot, || is false as soon as the value matches one item, so [gvlogic if="4" isnot="4||5||6"] is false.
HTML and other shortcodes inside [gvlogic] #
The content can hold HTML and other shortcodes:
[gvlogic if="{Number:5}" is="28"]
<strong>The number is 28.</strong>
[/gvlogic]A [gvlogic] can't go inside another [gvlogic]. Use the inner one as [gvlogic2], as in Using [gvlogic] and [gvlogic2] to create “AND” logic.
Troubleshooting #
If a condition returns the wrong content, check that every value has quotes around it. Write if="{Departments:11}", because if={Departments:11} may not be read correctly.
- Comparison parameters
- Showing something else when there's no match
- Comparing choice fields
- Showing content to signed-in users
- Checking a user's role
- Comparing numbers and dates
- Showing content on one screen of the View
- Combining values with || and &&
- HTML and other shortcodes inside [gvlogic]
- Troubleshooting