Using Logic Hop Shortcodes

Logic Hop Shortcodes have been deprecated.

Please use Logic Tags instead.

For ease-of-use, more powerful features and Gutenberg compatibility, please use Logic Tags in place of Logic Hop Shortcodes.

Existing Logic Hop Shortcodes will continue to function within WordPress.

Logic Hop Shortcodes allow you to easily add powerful conditional logic for content personalization with the click of a button.

Shortcodes Explained

Shortcodes are just that, short code. Think of it as a shortcut for writing actual code. Shortcodes are inserted in a WordPress post or page and replaced with the appropriate dynamic content.

While there are many types of Shortcodes, Logic Hop Shortcodes come in four varieties:

Conditional Shortcodes

Conditional Shortcodes display content when a Logic Hop Condition is true.

The Conditional Shortcode consists of two “blocks” of code which are place before and after the content you want to display. Almost any type of content or HTML can be placed between the blocks of code.

The Logic Hop Conditional Shortcode appears as:

[logichop_condition id=4 condition="today-is-friday"]
Happy Friday!
[/logichop_condition]

The Shortcode depicted above would display the text “Happy Friday!” when the Condition “Today is Friday” is true.

Multiple Conditional Shortcodes can be added to a page or post.

Conditional Shortcodes can contain other Shortcodes, but cannot contain another Conditional Shortcode.

Conditional Not Shortcodes

Conditional Not Shortcodes are they opposite of Conditional Shortcodes – They display content when a Logic Hop Condition is false.

The Conditional Not Shortcode also consists of two “blocks” of code which are place before and after the content you want to display. Almost any type of content or HTML can be placed between the blocks of code.

The Logic Hop Conditional Not Shortcode appears as:

[logichop_condition_not id=4 condition="today-is-friday"]
Sorry it's not Friday.
[/logichop_condition_not]

The Shortcode depicted above would display the text “Sorry it’s not Friday.” when the Condition “Today is Friday” is false.

Multiple Conditional Not Shortcodes can be added to a page or post.

Conditional Not Shortcodes can contain other Shortcodes, but cannot contain another Conditional Not Shortcode.

Goal Shortcodes

Goal Shortcodes trigger a Logic Hop Goal when the page or post is loaded.

The Logic Hop Goal Shortcode is a single block of code and appears as:

[logichop_goal goal=2 goal-name="newsletter-signup"]

The Shortcode depicted above would trigger the “Newsletter Signup” Goal for a user each time the page or post was loaded.

Multiple Goal Shortcodes can be added to a page or post.

Conditional Goal Shortcodes

Conditional Goal Shortcodes trigger a Logic Hop Goal when the page or post is loaded AND a specific Logic Hop Condition is true.

The Logic Hop Conditional Goal Shortcode is a single block of code and appears as:

[logichop_conditional_goal id=4 condition="today-is-friday" goal=2 goal-name="newsletter-signup"]

The Shortcode depicted above would trigger the “Newsletter Signup” Goal for a user each time the page or post was loaded AND the Condition “Today is Friday” is true.

Multiple Conditional Goal Shortcodes can be added to a page or post.

Data Shortcodes

Data Shortcodes allow Logic Hop data to be displayed to the user within a page.

The Logic Hop Data Shortcode is a single block of code and appears as:

[logichop_data var="Location.City"]

The Shortcode depicted above would display the name of the City from which the current user was visiting.

<strong>How's the weather in [logichop_data var="Location.City"]?</strong>

The Shortcode depicted above would display: How’s the weather in Ashburn?

Multiple Data Shortcodes can be added to a page or post. Data Shortcodes can also be nested within Conditional Shortcodes.

Data Input Shortcode Attributes:

  • var
    • Variable name – Example: Location.City
  • case
    • Change the case of the data output
    • Example: Using case=”lower” would change “New York City” to “new york city”
    • Options:
      • lower
      • upper
  • spaces
    • Replace spaces with specified character
    • Example: Using spaces=”_” would change “New York City” to “New-York-City”
    • Combine with case to format data for URLs and image SRC values
  • name
    • Name attribute of the input
  • class
    • CSS class attribute of the input

To display a Query String with in lowercase with spaces replaced with hyphens, use the following:

[logichop_data var="Location.City" case="lower" spaces="-"]

Data Input Shortcodes

Data Input Shortcodes work the same as Data Shortcodes, but instead of displaying data on the page, an HTML <input> element is generated with the data response as the input value. This technique is useful for pre-populating HTML forms with Logic Hop data.

Data Input Shortcodes can be inserted into pages and posts using the following format:

[logichop_data_input var="" type="" id="" name="" class=""]

Data Input Shortcode Attributes:

  • var
    • Variable name – Example: Location.City
  • type
    • Input type – Example: text, password, hidden
  • id
    • ID attribute of the input
  • name
    • Name attribute of the input
  • class
    • CSS class attribute of the input

Logic Hop Data via PHP

Logic Hop data can also be accessed via PHP for use in themes and plugins. Pass the variable name as a string into the $logichop->get_data() function.

Echo Logic Hop data via PHP:

global $logichop;
$logichop->get_data('Location.City');

Return Logic Hop data via PHP:

global $logichop;
$logichop->get_data('Location.City', false);

A list of Logic Hop variables can be viewed on the Condition Type & Operator Reference page.

Using Cache Plugins?

When using cache plugins, Conditional Shortcodes will produce unexpected results.

Click here to learn more about using Logic Hop with Cache Plugins.

Click here to learn how to use Logic Hop with Javascript.

Adding Shortcodes to Pages & Posts

The Logic Hop Shortcode Tool is the fastest and easiest way to add Shortcodes to your pages and posts.

Step 1

Click the Logic Hop button.

Step 2

Select the Condition, Goal or Data tab.

Step 3

Select your desired Shortcode type.

Step 4

Click the corresponding Insert Shortcode button.

Shortcode Tool

Step 5

Adjust the Shortcode “blocks” to around your content if necessary.

Shortcode Adjustment

Congratulations! Your Shortcode is now ready for use.