How to use a GravityView shortcode to show and hide content on a post, page, or View

Written by Zack Katz

Categories How-To

Tags , ,

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 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 shortcode works everywhere

Some GravityView functionality only works inside a View, but the shortcode works across your whole site: in posts, pages, Views, WordPress widgets…everywhere!

When you use 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 anywhere on your site

No matter where you use , you can use these Merge Tags to show or hide content:

GravityView Merge Tags

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


Show a message to logged-in user:

If you want to show a message on a page to logged-in users, you can use the shortcode, like this:

[​gvlogic if="{user:ID}" isnot=""]
  {user:display_name}, thanks for being logged in!

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"]


  Please fill out this form!

  [​gravityforms id="123"]


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!

The possibilities are endless for how to conditionally show and hide content on your site using the shortcode.

You can learn more about using GravityView on our Docs site.