Use Shortcodes to Show or Hide Content on a WordPress Page
Applies to: ONTRAPORT Plus and above.
Shortcodes work like macros in your WordPress posts, pages and ONTRAPORT Pages. You enter them on WordPress pages using the editor or on your ONTRAPORT Page. When the post or page is published they are replaced by the result of the shortcode. The shortcodes are used to refresh the member's information from ONTRAPORT, or show or hide content based on the membership level, Tag, or if the logged in WordPress user is recognized by ONTRAPORT. Shortcodes are available for ONTRAPORT Pages by adding to a text element with the shortcode or WordPress editor by using the Shortcode drop down box or manually typing it.
Add Shortcodes to a ONTRAPORT Page
Let's walk through an example of hiding content based on membership level. Imagine that you only wanted the Gold Members to see certain content in the membership area. You can protect entire pages based on membership level via Pilot Press. However, there may be situations where you want to only show certain content to certain membership levels and other content to another membership level.
In this example, we'll use individual blocks with text elements that include the shortcode to surround the area we would like to show certain content to gold members. You can also add shortcodes in a block or columns to protect partial sections. Experiment and test before launching!
- Add blocks above and below the content you'd like to show. Alternatively, you can add a row or even just a text element before and after.
- Insert text elements in the blocks
- Place the Shortcode above and below the area in which you would like to protect. In this example the top Shortcode is [show_if has_one='Gold'] and the bottom Shortcode is: [/show_if].
- Log into your WordPress site as an administrator and ensure the ONTRApages for WordPress plugin is installed.
- Navigate to ONTRApages > Add New
- Title the page and use the dropdown menu to select the ONTRAPORT Page you created
- Now the content "Ready to Talk..." will only be seen by those that are Gold members!
Add Login Form Shortcode to an ONTRAPORT Page
Give your members easy access to login using an ONTRAPORT page. Here's a quick way to achieve that, via a Shortcode
Add:[login_page] to your text element
Your membership login form will now magically appear on that page!
Using Shortcodes in the Pilot Press Editor
For showing and hiding content you add the membership level or Tag between the single quotes in the shortcode:
Using shortcodes allows you to have mixed content on the page, with some of the content visible to anyone and some of it only for a specific membership level or multiple levels ("Bronze" in the image above).
A special shortcode has been provided to resync the member's information in WordPress. This can be used to update their membership level and display content immediately after they fill out an order form in WordPress.
The Shortcode dropdown in the WordPress editor lists all of the available shortcodes:
Showing or Hiding Content Based on Membership Levels
In the following examples we are using the membership levels Bronze, Silver and Gold. The membership level we have added to the shortcode is shown in blue lettering. Each of these shortcodes will require editing to include the membership levels.
The word "content" is the content on the page you want to display or hide. The "content" can be text, images, videos, or any other content you normally have in a WordPress page or post. The "content" can be any length. If the shortcode is not active the "content" is not shown and does not take up space on the post or page the member sees.
+ Has one
This shortcode will display the content if the member has any of the membership levels (they do not have to have all of the membership levels).
What the editor inserts: [show_if has_one='']content[/show_if]
Edited to show to Bronze members only: [show_if has_one='Bronze']content[/show_if]
Edited to show to Bronze or Silver members but not Gold: [show_if has_one='Bronze, Silver']content[/show_if]
+ Has all
This shortcode limits the display to only those members who have ALL of the included membership levels. Having just some of the membership levels doesn't show the content:
What the editor inserts: [show_if has_all='']content[/show_if]
Edited to show to Bronze members only: [show_if has_all='Bronze']content[/show_if]
Edited to show to members with BOTH Bronze and Silver memberships: [show_if has_all='Bronze, Silver']content[/show_if]
A member with only Bronze membership will NOT see the content, as they must have BOTH Bronze and Silver.
+ Does not have one
The content inside the shortcode will be shown only if the member does NOT have ALL of the membership levels listed.
What the editor inserts: [show_if not_one='']content[/show_if]
Edited to show to members WITHOUT Bronze membership: [show_if not_one='Bronze']content[/show_if]
The content will be shown only to those members without Bronze membership (i.e, Silver and Gold members).
Edited to show only to Gold members: [show_if not_one='Bronze,Silver']content[/show_if]
The content is not shown to either Bronze, or Silver members, or members with both Bronze and Silver memberships.
+ Does not have any
For the content to show, the member must not have ANY of the membership levels listed.
What the editor inserts: [show_if not_any='']content[/show_if]
Edited to show to everyone without Bronze membership: [show_if not_any='Bronze']content[/show_if]
Edited to exclude anyone with either Bronze or Silver membership: [show_if not_any='Bronze,Silver']content[/show_if]
Only Gold membership levels will see this content.
Showing or Hiding Content Based on Tags
The member must be logged in for these shortcodes to display or hide content.
+ Has tag(s)
What the editor inserts: [show_if has_tag='']content[/show_if]
Edited to show to logged in members with the Tag "Action": [show_if has_tag='Action']content[/show_if]
+ Does not have tag
What the editor inserts: [show_if does_not_have_tag='']content[/show_if]
Edited to show content to logged in members who do NOT have the Tag "Action": [show_if does_not_have_tag='Action']content[/show_if]
Note: The member must be logged into WordPress for PilotPress to act and determine if the Tag exists. These shortcodes will not work for a Contact who is not logged into your membership site.
Showing or Hiding Content if Identified as an ONTRAPORT Contact
For logged in members only, these shortcodes can be used to display or hide content if the member is also a Contact in ONTRAPORT. These do not require any editing of the shortcode that is entered into the editor:
+ Is a contact
What the editor inserts: [show_if is_contact]content[/show_if]
No editing of this shortcode is necessary.
+ Is not a contact
What the editor inserts: [show_if not_contact]content[/show_if]
No editing of this shortcode is necessary.
Showing or Hiding Content Based on Cookie
These shortcodes will work even if the member is not logged in. PilotPress checks for the ONTRAPORT cookie on the domain and displays or hides the content based solely on the presence of that cookie.
+ Is a cookied contact
What the editor inserts: [show_if is_cookied_contact]content[/show_if]
No editing of this shortcode is necessary.
+ Is not a cookied contact
What the editor inserts: [show_if not_cookied_contact]content[/show_if]
No editing of this shortcode is necessary.
Resync contact and Sell Membership Usecase
This shortcode does not display or hide content. It retrieves information from ONTRAPORT when the page loads to resync the contact.
What the editor inserts: [pilotpress_sync_contact]
Note: This shortcode has built in looping protection to protect your site from multiple page refreshes. After the initial loading of the page the shortcode sets a timer and will accept two page refreshes in a five minute period. After the second page refresh the shortcode will be inactive for five minutes. This prevents a loop condition from slowing down or crashing your membership site.
Usecase: Sell Membership Level and Reveal the Content
In this usecase an ONTRAform order form on your WordPress site sells a new member level, and the member is given access without having to log out and back in. You will need to create:
- An ONTRAform order form designed in ONTRAPORT.
- A "sales page" inside your WordPress membership site.
- A "thank you" page inside your WordPress membership site.
Configuring the ONTRAform in the Settings dialog:
- Add the URL of the Thank You page on your site to the Custom URL option.
- Add a Rule that adds the membership level in the Rules: Successful Payment section.
- Check off the Redirect after immediate campaign and sequence steps run checkbox in the Advanced section.
Adding the ONTRAform to the "Sales Page"
Use the Add ONTRAPORT Media button to select and embed the ONTRAform into your sales page.
Add the shortcode to your Thank You page
After embedding your ONTRAform order form on your sales page, edit your thank you page and insert the [pilotpress_sync_contact] shortcode at the very top of the page by selecting it from the drop down
Shortcodes are executed by WordPress in the order they are presented on the page, so this shortcode should be at the very top of the page. It won't take up any room on the finished page that is displayed to the member so you don't have to add extra lines after it.
How this works: When the member fills out the ONTRAform order form and the charge is successful, the Rule adds the membership level to their Contact Record in ONTRAPORT. The checkbox setting for "Redirect after immediate ..." delays the showing of the Thank You page until the Rule has acted. When the Thank You page is displayed, the shortcode syncs the new membership information so the member can access their new membership content.
Testing Membership Levels and Shortcodes
The "PilotPress Admin View As" buttons allow you to view the page as a member with one membership level. These buttons become active after you have saved the post or page you are editing. Make sure your browser's pop up blocker is "off" for your WordPress admin section and click the membership level button. A new tab will open and the view will be as someone with that membership level. If your browser will not pop open the new tab, click to depress the membership level button and then click the preview button in the "Publish" section.
Because you can only test one membership level at a time you will not be able to test the shortcodes that require ALL of the membership levels to be present for the desired action such as [show_if has_all="Bronze,Silver"]content[/show_if]. For testing of multiple membership levels follow the process below.
Note: This process seems cumbersome but is necessary. Wordpress Administrators are cookied by WordPress. WordPress will read the Administrator's cookie even while logging in as another user. Private and incognito modes in your browser will not prevent WordPress from reading the Administrator cookie. Because of this, shortcodes and membership level protection may appear to fail if you don't follow this process.
- Create a new Contact for testing purposes. Add a Membership level to the contact. Keep ONTRAPORT open to this contact record.
- Open a new private tab or window in your browser (see instructions for Firefox and Chrome).
- In the private tab or window, clear the cookies for your Wordpress site. This step is required. To see instructions on how to clear your cookies, click HERE.
- Go to the default WordPress login page by adding "/wp-login.php" to your domain: http://your-domain.com/wp-login.php
- Log in as your new contact. Test the functionality of your membership levels and shortcodes.
- To test a new membership level, log the contact out of Wordpress. Add the new membership level in ONTRAPORT and log the contact back into Wordpress.
- You must use a private browsing window and clear your site's cookies in order to log in with a Contact's login credentials.
- You cannot nest the show_if tags due to a limitation of WordPress. "Nesting" refers to a structure like this:
Bronze and Silver member content here
- You cannot use PilotPress with any other membership plugin active.
- Plugins that manage redirection may conflict with PilotPress
- You must exclude the page or post protected by shortcodes from any cache plugins
Articles in this section
- WordPress Integration Overview
- Set up Membership Quick Start
- PilotPress Settings
- PilotPress and the WordPress Editor
- Integrate an Existing WordPress Site
- Integrate a New WordPress Site
- Migrate From Another Membership System to ONTRAPORT
- Creating Membership Levels
- Protect Content on Pages, Posts and Categories in WordPress
- Testing PilotPress Content Protection