Logic Hop Conditions

Quick Reference

Overview

Logic Hop Conditions are used to perform actions such as which content to display or when to set a goal.

Conditions can be thought of as questions answered by Logic Hop. Each question consists of one or more values which are compared by a comparison operator. The answer to a condition is either true or false which can be thought of as yes or no.

For example in the following condition, Day of the Week and Friday are the values and equal to is the comparison operator.

If the Day of the Week is Equal to Friday

View all condition types and comparison operators.

Anatomy of a Condition

Logic Hop Condition Builder

  • Condition Title
    • Used to generate Condition Slug – Example: today-is-friday
  • Condition Description
    • Describes Condition functionality
  • Conditional Statements
    • Defines functionality with:
      • Condition Types
      • Comparison Operators
  • Logic Tags
    • Logic Tag block to copy & paste into WordPress content areas
  • Condition Slug
    • WordPress slug – Used when working with Javascript & PHP
  • Enables Conditional CSS
  • CSS Classes

Creating a Condition

Condition Builder

  • Step 1
    • Click Conditions under the Logic Hop menu in your WordPress Dashboard
  • Step 2
    • Click Add New click the title a condition to edit
  • Step 3
    • Enter a title and description for the condition
      • It’s best to use short, descriptive titles such as Today is Friday
  • Step 4
    • Within the Conditional Statements section, select a Condition Type
  • Step 5
    • Select an Comparison Operator
  • Step 6
    • Select a Value
  • Step 7
    • Click Publish

Congratulations! Your condition is now ready for use.

Learn how to use conditions with pages & posts.

Note: Similar to page and post titles, the condition title becomes the slug for your condition. If you are using Conditional CSS or Javascript Tracking the slug may be visible in the source code of your page. For example, a condition titled Today is Friday may appear as a CSS class with the name .today-is-friday.

Creating a Multi-Statement Condition

Multi-Statement Conditions consist of two or more conditional statement blocks. Each block adds another question to the condition.

The blocks can be structured as And statements or Or statements:

  • And statements require all blocks are true
  • Or statements require only one block is true

Condition Builder – Multiple Conditions

  • Step 1
    • Click the + button to add a new conditional statement block
  • Step 2
    • Select the Statement Block Type
  • Step 3
    • Select a Condition Type
  • Step 4
    • Select an Comparison Operator
  • Step 5
    • Click Update

Congratulations! Your multi-statement condition is now ready for use.

Note: To remove a conditional statement block click the Remove link in the lower right corner of the block you want to delete.

Evaluate Conditions with Javascript

Conditions can be evaluated with Javascript for use in themes and plugins. Pass a condition slug or ID into the __logichop_condition( slug, true callback, false callback )__ function. If the condition is met the true callback is executed. If the condition is not met the false callback is executed.

The following example the true callback is executed if the condition today-is-friday is met. The false callback is executed if the condition is not met.

logichop_condition( 'today-is-friday', my_true_callback, my_false_callback );

function my_true_callback () {
  console.log( 'today-is-friday returned TRUE' );
}

function my_false_callback () {
  console.log( 'today-is-friday returned FALSE' );
}

Evaluate Conditions with PHP

Conditions can be evaluated with PHP for use in themes and plugins. Pass a condition slug or ID into the __$logichop->get_condition()__ function. If the condition is met, true is returned, if it is not met, false is returned.

The following example returns true if the condition slug today-is-friday is met or returns false if it is not met.

global $logichop;

$result = $logichop->get_condition( 'today-is-friday' );

Note: On sites where caching is in use conditions evaluated with PHP will be cached. To avoid caching, evaluate conditions with Javascript. Learn more about caching.

Deleting a Condition

  • Step 1
    • Click Conditions under the Logic Hop menu in your WordPress Dashboard.
  • Step 2
    • Click Trash under the title of the condition you want to delete.