Using conditions in the recipe template

Just getting started with the Template Editor? Check out the main documentation first!

Conditions can be used to show or hide specific parts of the template depending on certain conditions. There are 3 types of conditions that can be used right now, detailed in the different sections below:

  • Field conditions
  • Taxonomy conditions
  • Device conditions
  • User conditions

Important note: conditions will always show their content in the Template Editor preview. They will only work as expected on your actual site.

General usage of conditions

Conditions work by surrounding specific parts of the recipe template with the [wprm-condition][/wprm-condition] shortcode. You do this by going into "Edit HTML" in the Template Editor and literally typing that shortcode, using the correct attributes.

For example, here the template will display a disclaimer if the recipe has nutrition set:

See the sections below for the available attributes.

Once general attribute that can be added is inverse="1" which essentially inverses the condition:

[wprm-condition field="nutrition" inverse="1"]This text will show up if the recipe does NOT have nutrition values[/wprm-condition]

The inverse attribute can be combined with any of the attributes below. It is also possible to combine multiple of the attributes below. In that case, it will require all conditions to be met.

Using field conditions

A field condition can be used to show or hide a section of the recipe template if a certain field is present:

[wprm-condition field="image"]This text will show up if the recipe has an image[/wprm-condition]

These are currently the valid values for the field attribute:

  • image
  • video
  • nutrition
  • unit-conversion

Using taxonomy conditions

A taxonomy condition can be used to show or hide a section of the recipe template depending on the specific terms a recipe has associated with it:

[wprm-condition taxonomy="course" term_ids="4;10"]This text will show up if the recipe has the terms with ID 4 or 10 associated with it for the course taxonomy[/wprm-condition]

For the taxonomy attribute you'd use one of the recipe taxonomies:

  • course
  • cuisine
  • ingredient
  • ...

You then combine this with either term_ids="" or term_slugs="" as an attribute to define which terms that recipe should have. Multiple terms (with an OR relation) can be defined by splitting them with ;

Using device conditions

In some cases you might want to show specific text or features based on the device that a visitor is using:

[wprm-condition device="mobile;tablet"]This text will show up on mobile and tablet[/wprm-condition]

These are the valid values for the device attribute:

  • mobile
  • tablet
  • desktop

Devices can be combined by using ; as a separator.

Using user conditions

A user condition can be used to show or hide parts of the recipe template depending on the visitor's user status:

[wprm-condition user="logged_in"]This text will show up for logged in users only[/wprm-condition]

These are the valid values for the user attribute:

  • logged_in
  • logged_out
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.