Just getting started with the Template Editor?
Check out the Template Editor documentation first!
Conditions can be used to show or hide specific parts of the template depending on certain conditions. There are different types of conditions that can be used, detailed in the different sections below:
- Field conditions
- Taxonomy conditions
- Custom Field conditions
- Rating 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]
Examples of values that can be used for the field attribute:
- image
- video
- nutrition
- unit-conversion
- cost
- total_time
- …
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 custom field conditions
A custom field condition can be used to show or hide a section of the recipe template if a certain custom field is present:
[wprm-condition field="custom" key="your-custom-field"]This text will show up if a value is set for "your-custom-field"[/wprm-condition]
The key of the custom field can be found in the “key” column on the WP Recipe Maker > Manage > Your Custom Fields > Custom Fields page.
Using rating conditions
A rating condition can be used to show or hide a section of the recipe template depending on the average rating of a recipe:
[wprm-condition rating="0"]This text will show up if the recipe does not have any ratings yet[/wprm-condition]
[wprm-condition rating="4-5"]This text will show up if the recipe has a rating of 4 stars or more[/wprm-condition]
You can specify a range or an exact value. Take note that rating="3"
will not match an average recipe rating of 3.2, for example. You should use rating="3-3.999"
if you want to match a recipe that has at least 3 stars, but not 4 stars.
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