how to use GravityView's gvlogic shorcode to show or hide content

How to Use GravityView’s [gvlogic] Shortcode to Show or Hide Content on Your Website

Written by Casey Burridge

Last updated:

Categories GravityView

Tags

GravityView adds multiple shortcodes to WordPress, including the powerful “gvlogic” shortcode.

Using [gvlogic], you can show or hide content based on a range of different parameters. When you combine this functionality with specific merge tags, you can achieve some pretty neat results!

In this post, we’ll walk you through some examples of how to use [gvlogic] to show or hide content on your website. Let’s get started! 👇

The [gvlogic] Shortcode Works Everywhere

📝 What’s a shortcode? It’s a bit of text that you can add to your website that lets you perform complex functions without using code. Think of it like a shortcut! Shortcodes are wrapped in square brackets, like this: [example].

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 field values.

If you want to learn more about shortcodes in GravityView, check out the full list of GravityView shortcodes!

Use These Merge Tags With [gvlogic] Anywhere on Your Site

📝 Merge tags allow you to display dynamic content on your site. Most (but not all) merge tags rely on Gravity Forms field values.

No matter where you use [gvlogic], you can take advantage of these versatile Merge Tags to show or hide content on your website: 

Here are some relevant merge tags added by GravityView: 

Here are some relevant merge tags added by Gravity Forms:

  • {admin_email} – Display the email address of the site administrator
  • {admin_url} – Display the URL of the dashboard for the site
  • {logout_url} – Display the URL to log out of the site

Now let’s look at some examples of [gvlogic] in action.

Examples

So how do you use [gvlogic] together with the above merge tags to show/hide content based on certain conditions? Keep reading to find out as we tackle some practical examples below.

Show a Message to a 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 logged_in="true"]

{user:display_name}, thanks for being logged in!

[/​gvlogic]

As you can see, we’re using the logged_in parameter to check whether the user is logged in or out. If they are logged in, we’ll use the {user:display_name} merge tag to display their name followed by a quick message thanking them for being logged in.

So if the logged-in user’s display name was “Ellen Ripley”, they would see “Ellen Ripley, thanks for being logged in!”.

Hiding a Form for Logged-in Users

Let’s say you have a Gravity Form on your website for users to fill in. You want to show this form to logged-out users but not to logged-in users. You can do this by placing the Gravity Forms embed shortcode inside the [gvlogic] shortcode, like this:

[gvlogic logged_in=“false”]

[gravityforms id=“45”]

[/gvlogic]

Show a Form Only to Logged-Out Users, and a View to Logged-in Users

Here’s a slightly more complex example that builds on the previous one.

Let’s say you want to:

  1. Show a form to logged-out users but not to logged-in users. 
  2. Show logged-in users a View displaying the submitted form entries.

The below shortcode will display a Gravity Form to logged-out users, and will display a View containing the submitted entries to logged-in users:

[​gvlogic logged_in=”true”]

Here are the form submissions:

[​gravityview id="45"]

[else]

Please fill out this form!

[​gravityforms id="123"]

[/​gvlogic]

Displaying Content Only on Specific Pages

You can show/hide content on specific pages using the {current_post} merge tag with the ID modifier.

[gvlogic if="{current_post:ID}" is="49"] 

This content will only show on the page with ID #49

[/gvlogic]

The {current_post} merge tag accepts other modifiers too, including post_title, post_type and permalink.

Displaying a Link to the Entry Creator’s Profile Page in WordPress

Let’s say you had a View displaying Gravity Forms entries and you wanted to include a link back to the entry creator’s user profile. You can do this using the following shortcode:

[gvlogic if="{created_by}" isnot=""]

<a href="/wp-admin/user-edit.php?user_id={created_by:ID}">Link to Profile</a>

[/gvlogic]

As you can see, we’re using the {created_by:ID} merge tag inside the HTML anchor tag to construct the profile link dynamically.

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. To display specific content to users from Google Adwords, all you need to do is use the {get} merge tag to check for the gclid query parameter, like this:

[​gvlogic if="{get:gclid}" isnot=""]

Hey! We have a <em>special offer</em> for Google customers!

[/​gvlogic]

In other words, if the user’s URL includes the gclid query parameter, they will see a message saying “Hey! We have a special offer for Google customers!

Show or Hide Content Using [gvlogic]

In this post, we showed you how to conditionally show/hide content on your website using the [gvlogic] shortcode. [gvlogic] is one of the multiple shortcodes added to WordPress by the GravityView plugin.

By combining [gvlogic] with one or more merge tags, you can show/hide content based on a range of conditions! Check out our ultimate guide to learn more about conditional logic in Gravity Forms

Join Our Newsletter!📧🙌

✅ Helpful Gravity Forms content straight to your inbox

✅ Be the first to hear about new updates and releases