Shortcodes

Overview

WP Fusion includes a few shortcodes that let you display user meta, and show / hide content based on a user’s tags in your CRM.

Displaying user meta

You can use shortcodes to display meta data for logged in users. The syntax is pretty simple. For example, to show a user’s first name:

[user_meta field="first_name"]

Any field listed in the Contact Field tab of WP Fusion’s settings can be accessed in this way.

You can also display different information for users who haven’t registered yet, or aren’t logged in, like so:

Welcome, [user_meta field="first_name"]Guest[/user_meta]!

Logged in users will see their first name, while visitors will see “Welcome, Guest!

User meta formatting

WP Fusion supports formatting date and time fields using PHP’s date function. For example:

[user_meta field="next_bill_date" date-format="Y-m-d"]

This will output the date like 2019-03-10.

For escaping text in the date format, use a double backslash. For example:

[user_meta field="next_bill_date" date-format="l \\t\\h\\e jS \\o\\f F, Y"]

This will output the date like Friday the 22nd of March, 2019. For more information on the syntax see PHP’s date documentation.

Video – Displaying user meta

Displaying a contact ID

You can display the current user’s contact ID as well. The format is [user_meta field="{crm_slug}_contact_id"]. For example with Infusionsoft the shortcode would be:

[user_meta field="infusionsoft_contact_id"]

 

Displaying content based on tags

You can use these shortcodes to show and hide content based on a user’s logged in status and CRM tags.

Note that WP Fusion also includes support for Elementor, Beaver Builder, Divi, Oxygen, and the Gutenberg Editor. If you’re using a page builder it may be easier to configure access rules using WP Fusion’s visual interfaces rather than a shortcode.

Restricting content based on logged in status

You can use the following two shortcodes to show content based on whether or not a user is logged in, regardless of their tags. This works like:

[wpf_loggedin]Only visible to logged in users[/wpf_loggedin]
[wpf_loggedout]Only visible to logged out visitors[/wpf_loggedout]

Restricting content based on tags

To restrict content based on a user’s CRM tags, wrap the desired content in the WP Fusion shortcode, using the examples below.

This content will only show if the user is logged in and has the tag “New Customer”:

[wpf tag="New Customer"]Restricted Content[/wpf]

This content will only show if the user is logged in and has both the tags “New Customer” and “Purchased Course”:

[wpf tag="New Customer,Purchased Course"]Restricted Content[/wpf]

Show the content if a user does not have a tag

To show content only if a user doesn’t have a certain tag, use the following syntax:

[wpf not="New Customer"]Restricted Content[/wpf]

You can also combine multiple tags for the not parameter, like

[wpf not="New Customer, Active Member"]Restricted Content[/wpf]

In that case the content will be hidden if the user has any of the tags. So if the user is tagged either New Customer or Active Member, the content will be hidden.

You can also combine parameters for more advanced locking, like so:

[wpf tag="New Customer" not="Payment Failed"]Restricted Content[/wpf]

Requiring any tag, instead of all

By default, WP Fusion will only unlock the content if the user has all of the tags in the list. To make it so that the content will unlock when any of the tags are found, include method="any" in the shortcode, like:

[wpf tag="New Customer,Purchased Course" method="any"]Restricted Content[/wpf]

Else conditions

The [wpf] shortcode also supports an “else” condition. The usage works like:

[wpf tag="New Customer"]
Shows only to users with the "New Customer" tag
[else]
Shows to all logged in users who don't have the "New Customer" tag
[/wpf]

Logged out parameters

By default, content in the shortcode will always be hidden from users who aren’t logged in. You can change this by adding logged_out to the shortcode. For example:

[wpf not="New Customer" logged_out]
This will show to everyone who doesn't have the "New Customer" tag, including logged out visitors.
[/wpf]

or:

[wpf tag="New Customer" logged_out]
Shows only to users with the "New Customer" tag
[else]
Shows to all users who don't have the "New Customer" tag, as well as logged-out visitors.
[/wpf]

Displaying content based on page rules

Using the [[wpf_user_can_access]] shortcode, you can show and hide content based on the access rules configured in the WP Fusion meta box on another post.

For example, this shortcode shows a message only if the current user has permission to access a course with post ID 456.

[[wpf_user_can_access id="456"]
Thanks for signing up for Awesome Course!
[/wpf_user_can_access]]

Else conditions

This shortcode also accepts an [else] condition:

[[wpf_user_can_access id="456"]
Thanks for signing up for Awesome Course!
[else]
You might be interested in our Awesome Course
[/wpf_user_can_access]]

Within a loop

If the id= parameter is omitted, the shortcode will use the current post ID. This can be used in a loop or custom template to personalize the results.

For example to alternate the Elementor template displayed based on a user’s permissions:

[[wpf_user_can_access]

[elementor-template id="14331"] // Enrolled template

[else]

[elementor-template id="53371"] // Unenrolled template

[/wpf_user_can_access]]

Updating data

You can insert a shortcode into your pages to force an update of a users tags and/or meta data before the rest of the page is displayed.

This can be used to force a refresh of data from your CRM before displaying content using the [wpf] or [user_meta] shortcodes.

To force an update of the current user’s tags, use:

[wpf_update_tags]

To force an update of the current user’s meta data, use:

[wpf_update_meta]
Note that these shortcodes will trigger an API call to your CRM and slow down your page load by several seconds. They should be used sparingly, if at all.

Was this helpful?