Use [gvlogic] to show (or hide) content anywhere on your site
There's a much easier way to achieve the same results demonstrated on this page called "Field Conditional Logic".
Use our shortcode to show and hide content on your site
GravityView adds multiple shortcodes to WordPress ( see the list of GravityView shortcodes here), and one allows you to show or hide content based on rules you define: the [gvlogic] shortcode.
What's a shortcode? It's is a bit of text that you can add to your post or page that lets you perform complex functions without using code. A shortcode is a shortcut, and you can tell a shortcode because shortcodes are wrapped in square brackets, like this: [example]
.
The [gvlogic]
shortcode works everywhere
Some GravityView functionality only works inside a View, but the [gvlogic]
shortcode works across your whole site: in posts, pages, Views, WordPress widgets…everywhere!
When you use [gvlogic]
somewhere that isn't a View, you will be comparing values that aren't based on Gravity Forms data, so make sure to use Merge Tags that don't rely on form and field values.
Use these Merge Tags with with [gvlogic]
anywhere on your site
No matter where you use [gvlogic]
, you can use these Merge Tags to show or hide content:
GravityView Merge Tags
- {current_post} - Access details of the current post or page
- {user} - Access details of the current user
- {get} - Access details of the URL query string
Gravity Forms Merge Tags
{admin_email}
The email of the site administrator{admin_url}
The URL of the dashboard for the site{logout_url}
The URL to log out of the site
Examples
Show a message to the logged-in user:
If you want to show a message on a page to logged-in users, you can use the [gvlogic]
shortcode, like this:
[gvlogic if="{user:ID}" isnot=""] {user:display_name}, thanks for being logged in! [/gvlogic]
If the user's display name is "Ellen Ripley", when she is logged-in, she will see: "Ellen Ripley, thanks for being logged in!"
Show a form only to logged-out users, and a View to logged-in users
If you want to gather data for visitors and allow logged-in users of your site to see that content, you can do that with the following code. It will display a Gravity Forms form to logged-out users and will display the submitted entries in a GravityView View to logged-in users:
[gvlogic if="{user:ID}" isnot=""] Here are the form submissions: [gravityview id="45"] [else] Please fill out this form! [gravityforms id="123"] [/gvlogic]
Show content only to visitors arriving from Google Adwords
When a user visits your site from Google Adwords, they have ?gclid=xxxxxx
added to the URL. If you want to display content targeted only to them, you can:
[gvlogic if="{get:gclid}" isnot=""] Hi! We have a <em>special offer</em> for Google customers! [/gvlogic]
The possibilities are endless for how to conditionally show and hide content on your site using the [gvlogic]
shortcode.