WP Recipe Maker Shortcodes

Below, you’ll find a detailed guide on how to add the WP Recipe Maker Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WP Recipe Maker Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the WP Recipe Maker Plugin and the shortcodes it provides:

Plugin Icon
WP Recipe Maker

"WP Recipe Maker is a versatile WordPress plugin for food bloggers. It allows users to easily create, manage, and share beautiful, SEO-friendly recipes on their websites."

★★★★★ (284) Active Installs: 50000+ Tested with: 6.3.2 PHP Version: 5.4
Included Shortcodes:
  • [wprm-recipe-roundup-item]
  • [adjustable]
  • [timer]
  • [wprm-temperature]
  • [wprm-glossary]
  • [wprm-ingredient]
  • [wprm-condition]
  • [wprm-recipe-snippet]
  • [wprm-recipe]
  • [seo_recipe]
  • [nutrition-label]

WP Recipe Maker [wprm-recipe-roundup-item] Shortcode

The WP Recipe Maker shortcode is used for displaying recipe details. It allows customization of recipe attributes, such as alignment, image, summary, and name. It can handle both internal and external recipes. If the recipe ID is provided, it fetches the recipe details internally. For external recipes, it accepts a link and additional details. The shortcode also includes parameters for button text, template, nofollow attribute, and new tab opening. It ensures only published recipes are displayed, providing an option for Gutenberg preview.

Shortcode: [wprm-recipe-roundup-item]

Parameters

Here is a list of all possible wprm-recipe-roundup-item shortcode parameters and attributes:

  • id – The unique identifier of the recipe
  • align – Aligns the recipe content
  • link – Provides a link to the recipe
  • image – Inserts the recipe image ID
  • image_url – Direct link to the recipe image
  • summary – Brief description of the recipe
  • name – Names the recipe
  • button – Adds a button to the recipe
  • template – The template used for the recipe
  • nofollow – Prevents search engines from following links
  • newtab – Opens the recipe link in a new tab

Examples and Usage

Basic example – Display a recipe by referencing its ID.

[wprm-recipe-roundup-item id=1 /]

Advanced examples

Display a recipe by referencing its ID and aligning it to the left. The recipe will be loaded by ID and aligned to the left side of the page.

[wprm-recipe-roundup-item id=1 align="left" /]

Display a recipe by referencing its ID, aligning it to the right, and adding a custom name and summary. The recipe will be loaded by ID, aligned to the right side of the page, and the name and summary will be replaced with the provided values.

[wprm-recipe-roundup-item id=1 align="right" name="My Custom Recipe Name" summary="This is a short summary of the recipe." /]

Display a recipe by referencing its ID, aligning it to the center, adding a custom name, summary, and button text. The recipe will be loaded by ID, aligned to the center of the page, and the name, summary, and button text will be replaced with the provided values.

[wprm-recipe-roundup-item id=1 align="center" name="My Custom Recipe Name" summary="This is a short summary of the recipe." button="Click Here for Recipe" /]

Display a recipe by referencing its ID, aligning it to the left, adding a custom name, summary, button text, and using a custom template. The recipe will be loaded by ID, aligned to the left side of the page, the name, summary, and button text will be replaced with the provided values, and the template will be loaded from the specified template slug.

[wprm-recipe-roundup-item id=1 align="left" name="My Custom Recipe Name" summary="This is a short summary of the recipe." button="Click Here for Recipe" template="my_custom_template" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wprm-recipe-roundup-item] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wprm-recipe-roundup-item', array( __CLASS__, 'shortcode' ) );

Shortcode PHP function:

function shortcode( $atts ) {
		$atts = shortcode_atts(
			array(
				'id' => false,
				'align' => '',
				'link' => '',
				'image' => '',
				'image_url' => '',
				'summary' => '',
				'name' => '',
				'button' => '',
				'template' => '',
				'nofollow' => false,
				'newtab' => true,
			),
			$atts,
			'wprm_recipe_roundup_item'
		);

		$recipe = false;
		$recipe_template = trim( $atts['template'] );
		$recipe_id = intval( $atts['id'] );
		self::$roundup_overrides = array();

		if ( $recipe_id ) {
			$type = 'internal';
			$recipe = WPRM_Recipe_Manager::get_recipe( $recipe_id );

			if ( $atts['name'] ) 	{ self::$roundup_overrides['name'] = rawurldecode( $atts['name'] ); }
			if ( $atts['summary'] ) { self::$roundup_overrides['summary'] = rawurldecode( str_replace( '%0A', '<br/>', $atts['summary'] ) ); }

			// Only display published recipes.
			if ( WPRM_Settings::get( 'recipe_roundup_published_only' ) ) {
				if ( $recipe && 'publish' !== $recipe->post_status() ) {
					// If not in Gutenberg preview, return empty shortcode.
					if ( ! isset( $GLOBALS['wp']->query_vars['rest_route'] ) || '/wp/v2/block-renderer/wp-recipe-maker/recipe-roundup-item' !== $GLOBALS['wp']->query_vars['rest_route'] ) {
						return '';
					}
				}
			}
		} else {
			$type = 'external';
			$recipe_data = array(
				'type' => 'food',
				'parent_id' => true,
				'parent_url' => rawurldecode( $atts['link'] ),
				'permalink' => rawurldecode( $atts['link'] ),
				'name' => rawurldecode( $atts['name'] ),
				'summary' => rawurldecode( str_replace( '%0A', '<br/>', $atts['summary'] ) ),
				'parent_url_new_tab' => $atts['newtab'] ? true : false,
				'parent_url_nofollow' => $atts['nofollow'] ? true : false,
			);

			$image_id = intval( $atts['image'] );
			if ( -1 === $image_id ) {
				$recipe_data['image_id'] = 'url';
				$recipe_data['image_url'] = $atts['image_url'];
			} else {
				$recipe_data['image_id'] = $image_id;
			}

			$recipe = new WPRM_Recipe_Shell( $recipe_data );
		}

		// Both internal and external.
		if ( $atts['button'] ) { self::$roundup_overrides['roundup_link_button_text'] = rawurldecode( $atts['button'] ); }

		if ( $recipe ) {
			$template = false;
			$template_slug = trim( $atts['template'] );

			if ( $template_slug ) {
				$template = WPRM_Template_Manager::get_template_by_slug( $template_slug );
			}

			if ( ! $template ) {
				$template = WPRM_Template_Manager::get_template_by_type( 'roundup', $recipe->type() );
			}

			if ( $template ) {
				// Add to used templates.
				WPRM_Template_Manager::add_used_template( $template );

				$align_class = '';
				if ( isset( $atts['align'] ) && $atts['align'] ) {
					$align_class = ' align' . esc_attr( $atts['align'] );
				}

				$output = '<div class="wprm-recipe wprm-recipe-roundup-item wprm-recipe-roundup-item-' . esc_attr( $recipe->id() ) . ' wprm-recipe-template-' . esc_attr( $template['slug'] ) . esc_attr( $align_class ) . '" data-servings="' . esc_attr( $recipe->servings() ). '">';

				// Add filters for overrides and immediately remove after doing shortcode.
				add_filter( 'wprm_recipe_roundup_link_text', array( __CLASS__, 'roundup_link_text_override' ) );
				if ( 'internal' === $type ) {
					add_filter( 'wprm_recipe_field', array( __CLASS__, 'recipe_field_overrides' ), 10, 2 );
					WPRM_Template_Shortcodes::set_current_recipe_id( $recipe->id() );
					$output .= do_shortcode( $template['html'] );
					WPRM_Template_Shortcodes::set_current_recipe_id( false );
					remove_filter( 'wprm_recipe_field', array( __CLASS__, 'recipe_field_overrides' ), 10, 2 );
				} else {
					WPRM_Template_Shortcodes::set_current_recipe_shell( $recipe );
					$output .= do_shortcode( $template['html'] );
					WPRM_Template_Shortcodes::set_current_recipe_shell( false );
				}
				remove_filter( 'wprm_recipe_roundup_link_text', array( __CLASS__, 'roundup_link_text_override' ) );

				$output .= '</div>';

				return $output;
			}
		}

		return '';
	}

Code file location:

wp-recipe-maker/wp-recipe-maker/includes/public/class-wprm-recipe-roundup.php

WP Recipe Maker [adjustable] Shortcode

The WP Recipe Maker ‘adjustable’ shortcode is used to create dynamic quantity adjustments in recipes. It wraps the content within a span element.

Shortcode: [adjustable]

Examples and Usage

Basic example – Displays a span element with the class “wprm-dynamic-quantity” containing the content specified within the shortcode.

[adjustable]Your Content Here[/adjustable]

Advanced examples

Example 1: Using the shortcode to display a dynamic quantity for a recipe ingredient. The quantity will be wrapped within a span that has the class “wprm-dynamic-quantity”. This allows the quantity to be dynamically adjusted with the WP Recipe Maker plugin.

[adjustable]2 cups[/adjustable]

Example 2: Using the shortcode to display multiple dynamic quantities for a recipe. Each quantity is wrapped within its own span with the class “wprm-dynamic-quantity”. This allows each quantity to be independently adjusted with the WP Recipe Maker plugin.

[adjustable]2 cups[/adjustable] of flour and [adjustable]1 cup[/adjustable] of sugar

Note: In these examples, the “atts” parameter is not used in the shortcode. The content enclosed within the shortcode is directly displayed as is, wrapped within a span with the class “wprm-dynamic-quantity”.

PHP Function Code

In case you have difficulties debugging what causing issues with [adjustable] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'adjustable', array( __CLASS__, 'adjustable_shortcode' ) );

Shortcode PHP function:

function adjustable_shortcode( $atts, $content ) {
		return '<span class="wprm-dynamic-quantity">' . $content . '</span>';
	}

Code file location:

wp-recipe-maker/wp-recipe-maker/includes/public/class-wprm-shortcode-other.php

WP Recipe Maker [timer] Shortcode

The WP Recipe Maker shortcode ‘timer’ sets a timer for recipes. It accepts seconds, minutes, and hours as attributes, converting them into total seconds. If a time is set, it displays a countdown timer. If no time is set, it simply returns the content.

Shortcode: [timer]

Parameters

Here is a list of all possible timer shortcode parameters and attributes:

  • seconds – The number of seconds for the timer
  • minutes – The number of minutes converted into seconds for the timer
  • hours – The number of hours converted into seconds for the timer

Examples and Usage

Basic Example – A simple timer shortcode that sets the timer for 30 seconds.

[timer seconds=30]

Advanced Examples

Setting a timer for 2 minutes and 30 seconds using the shortcode. The timer will first calculate the total seconds from the minutes and seconds parameters.

[timer minutes=2 seconds=30]

Using the shortcode to set a timer for 1 hour, 30 minutes, and 45 seconds. The timer will first calculate the total seconds from the hours, minutes, and seconds parameters.

[timer hours=1 minutes=30 seconds=45]

Setting a timer for 2 hours using the shortcode. The timer will first calculate the total seconds from the hours parameter.

[timer hours=2]

Using the shortcode to set a timer for 45 seconds. If no seconds are provided, the timer will default to 0 seconds.

[timer seconds=45]

PHP Function Code

In case you have difficulties debugging what causing issues with [timer] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'timer', array( __CLASS__, 'timer_shortcode' ) );

Shortcode PHP function:

function timer_shortcode( $atts, $content ) {
		$atts = shortcode_atts( array(
			'seconds' => '0',
			'minutes' => '0',
			'hours' => '0',
		), $atts, 'wprm_timer' );

		$seconds = intval( $atts['seconds'] );
		$minutes = intval( $atts['minutes'] );
		$hours = intval( $atts['hours'] );

		$seconds = $seconds + (60 * $minutes) + (60 * 60 * $hours);

		if ( $seconds > 0 ) {
			return '<span class="wprm-timer" data-seconds="' . esc_attr( $seconds ) . '">' . $content . '</span>';
		} else {
			return $content;
		}
	}

Code file location:

wp-recipe-maker/wp-recipe-maker/includes/public/class-wprm-shortcode-other.php

WP Recipe Maker [wprm-temperature] Shortcode

The WP Recipe Maker shortcode is a feature that allows the display of temperature in a recipe. It accepts parameters like icon, value, unit, and help. It sanitizes and verifies the value before output. If the value is not set, it returns an empty string. The shortcode also supports tooltips, which are activated by the ‘help’ parameter. The output includes the temperature value and unit (Celsius or Fahrenheit) and can optionally display an icon. The shortcode is flexible, allowing customization to fit your recipe display needs.

Shortcode: [wprm-temperature]

Parameters

Here is a list of all possible wprm-temperature shortcode parameters and attributes:

  • icon – Specifies the icon to be displayed with the temperature.
  • value – The actual numeric value of the temperature.
  • unit – Defines the unit of temperature, default is set in the plugin settings.
  • help – An optional tooltip text that appears when hovering over the temperature.

Examples and Usage

Basic example – Presenting a recipe temperature using the WP Recipe Maker temperature shortcode.

[wprm-temperature value="350" unit="F" /]

This shortcode will output the temperature value 350 with the unit Fahrenheit (F) on your recipe page.

Advanced examples – Displaying a recipe temperature with an icon and tooltip help text.

[wprm-temperature icon="oven" value="180" unit="C" help="Preheat oven to this temperature" /]

In this advanced usage example, the shortcode will output the temperature value 180 with the unit Celsius (C). It will also display an oven icon (assuming the icon file ‘oven.svg’ exists in the plugin’s ‘assets/icons/temperature/’ directory). Additionally, a tooltip will appear when the user hovers over the temperature, displaying the text “Preheat oven to this temperature”.

PHP Function Code

In case you have difficulties debugging what causing issues with [wprm-temperature] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wprm-temperature', array( __CLASS__, 'temperature_shortcode' ) );

Shortcode PHP function:

function temperature_shortcode( $atts ) {
		$atts = shortcode_atts( array(
			'icon' => '',
			'value' => '',
			'unit' => WPRM_Settings::get( 'default_temperature_unit' ),
			'help' => '',
		), $atts, 'wprm_temperature' );

		// Value needs to be set.
		if ( '' === $atts['value'] ) {
			return '';
		}

		$icon = sanitize_key( $atts['icon'] );
		$value = $atts['value'];
		$unit = strtoupper( sanitize_key( $atts['unit'] ) );
		$help = sanitize_text_field( $atts['help'] );

		// Classes.
		$classes = array(
			'wprm-temperature-container',
		);

		if ( $atts['help'] ) {
			$classes[] = 'wprm-tooltip';
		}

		// Construct data.
		$data = '';
		$data .= ' data-value="' . esc_attr( $value ) .  '"';
		$data .= ' data-unit="' . esc_attr( $unit ) .  '"';
		$data .= ' data-tooltip="' . esc_attr( $help ) .  '"';

		// Construct output.
		$output = '';
		$output .= '<span class="' . implode( ' ', $classes ) . '"' . $data . '>';

		// Icon output
		if ( $icon && file_exists( WPRM_DIR . 'assets/icons/temperature/' . $icon . '.svg' ) ) {
			$output .= '<span class="wprm-temperature-icon">';
			$output .= '<img src="' . WPRM_URL . 'assets/icons/temperature/' . $icon . '.svg" alt="' . esc_attr( $help ) . '">';
			$output .= '</span>';
		}

		// Value output
		$output .= '<span class="wprm-temperature-value">';
		$output .= esc_html( $value );
		$output .= '</span>';

		// Unit output
		if ( in_array( $unit, array( 'C', 'F' ) ) ) {
			$output .= '<span class="wprm-temperature-unit">';
			switch ( $unit ) {
				case 'C':
					$output .= ' °C';
					break;
				case 'F':
					$output .= ' °F';
					break;
			}
			$output .= '</span>';
		}

		$output .= '</span>';

		return apply_filters( 'wprm_temperature_shortcode', $output, $atts );
	}

Code file location:

wp-recipe-maker/wp-recipe-maker/includes/public/class-wprm-shortcode-other.php

WP Recipe Maker [wprm-glossary] Shortcode

The WP Recipe Maker shortcode ‘wprm-glossary’ is designed to fetch and display glossary terms from your WordPress site. It allows you to specify a term ID to retrieve the relevant term. This shortcode also provides an optional tooltip feature. If the glossary term has a description, it will be displayed as a tooltip when the term is hovered over. The term name is displayed within a span element, with the classes ‘wprm-glossary-term’ and ‘wprm-glossary-term-{term_id}’ for styling purposes. In the absence of a specified term ID, the shortcode will simply return the original content passed to it. The glossary term and its description are both sanitized before being included in the output, ensuring safe and secure usage.

Shortcode: [wprm-glossary]

Parameters

Here is a list of all possible wprm-glossary shortcode parameters and attributes:

  • id – Unique identifier for the glossary term to be displayed.

Examples and Usage

Basic example – The shortcode displays a glossary term by referencing its ID. The term’s name will be shown, and if a description is available, it will be displayed as a tooltip when hovering over the term.

[wprm-glossary id=1 /]

Advanced examples

Using the shortcode to display a glossary term by referencing its ID and providing an alternative text. If the term is found, the alternative text will be shown instead of the term’s name. If a description is available, it will be displayed as a tooltip when hovering over the term.

[wprm-glossary id=1]Alternative Text[/wprm-glossary]

Using the shortcode without specifying an ID. If the term is not found by ID, the shortcode will try to display the term based on the content within the shortcode tags. If a description is available, it will be displayed as a tooltip when hovering over the term.

[wprm-glossary]Glossary Term[/wprm-glossary]

PHP Function Code

In case you have difficulties debugging what causing issues with [wprm-glossary] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wprm-glossary', array( __CLASS__, 'glossary_shortcode' ) );

Shortcode PHP function:

function glossary_shortcode( $atts, $content ) {
		$atts = shortcode_atts( array(
			'id' => '',
		), $atts, 'wprm_glossary' );

		$id = intval( $atts['id'] );
		$original_text = $content ? $content : '';
		$term = $id ? get_term( $id, 'wprm_glossary_term' ) : false;

		$output = '';

		if ( $term ) {
			$name = $original_text ? $original_text : $term->name;

			if ( $name ) {
				$classes = array(
					'wprm-glossary-term',
					'wprm-glossary-term-' . $term->term_id,
				);

				$tooltip = $term->description;
				$data_tooltip = '';

				if ( $tooltip ) { 
					$classes[] = 'wprm-tooltip';
					$data_tooltip = ' data-tooltip="' . esc_attr( $tooltip ) . '"';
				}

				$output = '<span class="' . esc_attr( implode( ' ', $classes ) ) . '"' . $data_tooltip . '>' . $name . '</span>';
			}
		}

		return $output;
	}

Code file location:

wp-recipe-maker/wp-recipe-maker/includes/public/class-wprm-shortcode-other.php

WP Recipe Maker [wprm-ingredient] Shortcode

The WP Recipe Maker shortcode allows you to display specific ingredient details within your recipe. It extracts the ingredient’s name, amount, and unit from the recipe database. This shortcode uses the ingredient’s unique ID to fetch its details. It also supports customization of text style and color, and offers unit conversion options.

Shortcode: [wprm-ingredient]

Parameters

Here is a list of all possible wprm-ingredient shortcode parameters and attributes:

  • id – the unique identifier of the recipe
  • uid – unique identifier for the ingredient in the recipe
  • text – default text to display if ingredient not found
  • style – defines the display style of the ingredient text
  • color – changes the color of the ingredient text
  • unit_conversion – shows a second unit system for the ingredient
  • unit_conversion_both_style – not in use in the provided code
  • unit_conversion_show_identical – not in use in the provided code

Examples and Usage

Basic example – Displaying a specific ingredient by its unique ID from a particular recipe.

[wprm-ingredient id="123" uid="1" /]

Here, ‘123’ is the ID of the recipe and ‘1’ is the unique ID of the ingredient in that recipe. This shortcode will display the ingredient with its amount and unit.

Advanced examples

Displaying an ingredient with a custom text style and color.

[wprm-ingredient id="123" uid="1" style="italic" color="#FF0000" /]

In this example, the ‘style’ attribute is set to ‘italic’, which will display the ingredient in italic font. The ‘color’ attribute is set to ‘#FF0000’, which will display the ingredient in red color.

Displaying an ingredient with unit conversion.

[wprm-ingredient id="123" uid="1" unit_conversion="both" /]

This shortcode will display the ingredient with its amount and unit, and also the converted amount and unit if available. The ‘unit_conversion’ attribute is set to ‘both’, which means it will show both the original and converted units.

PHP Function Code

In case you have difficulties debugging what causing issues with [wprm-ingredient] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wprm-ingredient', array( __CLASS__, 'ingredient_shortcode' ) );

Shortcode PHP function:

function ingredient_shortcode( $atts ) {
		$atts = shortcode_atts( array(
			'id' => '',
			'uid' => '',
			'text' => '',
			'style' => 'bold',
			'color' => '',
			'unit_conversion' => '',
			'unit_conversion_both_style' => '',
			'unit_conversion_show_identical' => '',
		), $atts, 'wprm_ingredient' );

		// Default to text as output.
		$output = WPRM_Shortcode_Helper::sanitize_html( $atts['text'] );

		// Get recipe (defaults to current).
		$recipe = WPRM_Template_Shortcodes::get_recipe( $atts['id'] );

		if ( $recipe && is_numeric( $atts['uid'] ) ) {
			$uid = intval( $atts['uid'] );

			$ingredients_flat = $recipe->ingredients_flat();
			$index = array_search( $uid, array_column( $ingredients_flat, 'uid' ) );

			if ( false !== $index && isset( $ingredients_flat[ $index ] ) ) {
				$found_ingredient = $ingredients_flat[ $index ];

				if ( 'ingredient' === $found_ingredient['type'] ) {
					$parts = array();

					if ( $found_ingredient['amount'] ) { $parts[] = $found_ingredient['amount']; };
					if ( $found_ingredient['unit'] ) { $parts[] = $found_ingredient['unit']; };

					// Optionally add second unit system.
					$show_both_units = 'both' === $atts['unit_conversion'];
					if ( $show_both_units ) {
						$amount_unit = apply_filters( 'wprm_recipe_ingredients_shortcode_amount_unit', implode( ' ', $parts ), $atts, $found_ingredient );
					}

					if ( $found_ingredient['name'] ) { $parts[] = $found_ingredient['name']; };

					$text_to_show = implode( ' ', $parts );

					if ( $text_to_show ) {
						$classes = array(
							'wprm-inline-ingredient',
							'wprm-inline-ingredient-' . $recipe->id() . '-' . $uid,
							'wprm-block-text-' . $atts['style'],
						);

						// Custom CSS style.
						$style = '';

						if ( $atts['color'] ) {
							$style = ' style="color: ' . esc_attr( $atts['color'] ) . ';"';
						}

						// Needed to show both units?
						if ( $show_both_units ) {
							$text_to_show = $amount_unit . ' ' . $found_ingredient['name'];
						}
					
						$output = '<span class="' . esc_attr( implode( ' ', $classes ) ) .'"' . $style . '>' . $text_to_show . '</span>';
					}
				}
			}
		}

		return $output;
	}

Code file location:

wp-recipe-maker/wp-recipe-maker/includes/public/class-wprm-shortcode-other.php

WP Recipe Maker [wprm-condition] Shortcode

The WP Recipe Maker shortcode enables condition-based content display. It checks for specific recipe fields, user status, or device type. The shortcode verifies if a recipe has an image, video, nutrition info, or unit conversion. It also checks if the user is logged in or the device used. Depending on the conditions met, it either displays the content or returns empty.

Shortcode: [wprm-condition]

Parameters

Here is a list of all possible wprm-condition shortcode parameters and attributes:

  • id – Unique identifier for the recipe.
  • field – Defines the condition based on recipe characteristics, such as image, video, nutrition, or unit-conversion.
  • device – Checks the device used to view the recipe. Can be desktop, mobile, or tablet.
  • user – Checks the user status; either logged in or guest (logged out).
  • inverse – If set to ‘1’, conditions will be reversed. Default is ‘0’.

Examples and Usage

Basic example – The shortcode is used to display specific content based on a condition. Here, the ‘id’ attribute is used to specify the recipe id.

[wprm-condition id="1" /]

Advanced examples

Using the shortcode to display specific content based on the field condition. Here, ‘field’ attribute is used to specify the condition field and ‘id’ attribute to specify the recipe id. If the condition field is ‘image’, the shortcode will check whether the recipe has an image or not.

[wprm-condition id="1" field="image" /]

Using the shortcode to display specific content based on the device condition. Here, ‘device’ attribute is used to specify the condition device and ‘id’ attribute to specify the recipe id. If the condition device is ‘mobile’, the shortcode will check whether the current device is mobile or not.

[wprm-condition id="1" device="mobile" /]

Using the shortcode to display specific content based on the user condition. Here, ‘user’ attribute is used to specify the condition user and ‘id’ attribute to specify the recipe id. If the condition user is ‘logged_in’, the shortcode will check whether the user is logged in or not.

[wprm-condition id="1" user="logged_in" /]

Using the shortcode to display specific content based on multiple conditions. Here, ‘field’, ‘device’, and ‘user’ attributes are used to specify the condition field, device, and user respectively and ‘id’ attribute to specify the recipe id. The shortcode will check whether all the conditions are met or not.

[wprm-condition id="1" field="image" device="mobile" user="logged_in" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wprm-condition] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wprm-condition', array( __CLASS__, 'condition_shortcode' ) );

Shortcode PHP function:

function condition_shortcode( $atts, $content ) {
		$atts = shortcode_atts( array(
			'id' => '0',
			'field' => '',
			'device' => '',
			'user' => '',
			'inverse' => '0',
		), $atts, 'wprm_condition' );

		$recipe = WPRM_Template_Shortcodes::get_recipe( $atts['id'] );

		$matches_conditions = array();

		// Field conditions.
		if ( $atts['field'] ) {
			$field_condition = strtolower( $atts['field'] );
			$recipe = WPRM_Template_Shortcodes::get_recipe( $atts['id'] );

			if ( $recipe ) {
				switch ( $field_condition ) {
					case 'image':
						$matches_conditions[] = 0 < $recipe->image_id();
						break;
					case 'video':
						$matches_conditions[] = '' !== $recipe->video();
						break;
					case 'nutrition':
						$matches_conditions[] = '' !== do_shortcode( '[wprm-nutrition-label id="' . $recipe->id() . '"]' );
						break;
					case 'unit-conversion':
						$matches_conditions[] = '' !== do_shortcode( '[wprm-recipe-unit-conversion id="' . $recipe->id() . '"]' );
						break;
				}
			}
		}

		// Device conditions.
		if ( $atts['device'] ) {
			if ( ! class_exists( 'Mobile_Detect' ) ) {
				require_once( WPRM_DIR . 'vendor/Mobile-Detect/Mobile_Detect.php' );
			}

			if ( class_exists( 'Mobile_Detect' ) ) {
				$detect = new Mobile_Detect;

				// Check current device.
				$device = 'desktop';
				if ( $detect && $detect->isMobile() ) { $device = 'mobile'; }
				if ( $detect && $detect->isTablet() ) { $device = 'tablet'; }

				$device_condition = strtolower( str_replace( ',', ';', $atts['device'] ) );
				$matches_conditions[] = in_array( $device, explode( ';', $device_condition ) );
			}
		}

		// User conditions.
		if ( $atts['user'] ) {
			$user_condition = strtolower( str_replace( '-', '_', $atts['user'] ) );

			switch( $user_condition ) {
				case 'logged_in':
					$matches_conditions[] = is_user_logged_in();
					break;
				case 'guest':
				case 'logged_out':
					$matches_conditions[] = ! is_user_logged_in();
					break;
			}
		}

		// Combine conditions.
		if ( 0 < count( $matches_conditions ) ) {
			$match = true;
			foreach( $matches_conditions as $matches_condition ) {
				$match = $match && $matches_condition;
			}
		} else {
			$match = false;
		}
		
		// Optional inverse match.
		if ( (bool) $atts['inverse'] ) {
			$match = ! $match;
		}

		// Return content if it matches the condition, empty otherwise.
		if ( $match ) {
			return do_shortcode( $content );
		} else {
			return '';
		}
	}

Code file location:

wp-recipe-maker/wp-recipe-maker/includes/public/class-wprm-shortcode-other.php

WP Recipe Maker [wprm-recipe-snippet] Shortcode

The WP Recipe Maker shortcode is a tool that dynamically generates recipe snippets. It uses the ‘wprm-recipe-snippet’ shortcode to display recipe details. This shortcode retrieves the recipe ID and template style. Depending on the page type, it aligns the snippet and applies the chosen template. If no template is specified, it defaults to the recipe type. The shortcode also resets the recipe ID after use.

Shortcode: [wprm-recipe-snippet]

Parameters

Here is a list of all possible wprm-recipe-snippet shortcode parameters and attributes:

  • id – Specifies the unique identifier of the recipe.
  • template – Defines the specific template to use for the recipe.

Examples and Usage

Basic example – Display a recipe snippet by referencing the recipe id.

[wprm-recipe-snippet id=1 /]

Advanced examples

Display a recipe snippet by referencing the recipe id and specifying a custom template.

[wprm-recipe-snippet id=1 template="custom-template" /]

Display a recipe snippet by only specifying a custom template. The recipe id will be determined based on the current post.

[wprm-recipe-snippet template="custom-template" /]

Display a recipe snippet by referencing the recipe id. The template will be determined based on the type of the recipe.

[wprm-recipe-snippet id=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wprm-recipe-snippet] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wprm-recipe-snippet', array( __CLASS__, 'recipe_snippet_shortcode' ) );

Shortcode PHP function:

function recipe_snippet_shortcode( $atts ) {
		$atts = shortcode_atts( array(
			'id' => '',
			'template' => '',
		), $atts, 'wprm_recipe_snippet' );

		if (
				( ! is_feed() && ! is_front_page() && is_singular() && is_main_query() )
				|| ( isset( $GLOBALS['wp']->query_vars['rest_route'] ) && '/wp/v2/block-renderer/wp-recipe-maker/recipe-snippet' === $GLOBALS['wp']->query_vars['rest_route'] )
		) {
			$recipe_id = $atts['id'] ? $atts['id'] : WPRM_Template_Shortcodes::get_current_recipe_id();

			if ( $recipe_id ) {
				WPRM_Assets::load();

				// Set current recipe ID to make sure it outputs for the correct recipe.
				if ( $atts['id'] ) {
					WPRM_Template_Shortcodes::set_current_recipe_id( $recipe_id );
				}

				if ( 'legacy' === WPRM_Settings::get( 'recipe_template_mode' ) ) {
					$alignment = WPRM_Settings::get( 'recipe_snippets_alignment' );
					return '<div class="wprm-recipe-snippets" style="text-align: ' . esc_attr( $alignment ) . ';">' . do_shortcode( WPRM_Settings::get( 'recipe_snippets_text' ) ) . '</div>';
				} else {
					$template = false;
					$template_slug = trim( $atts['template'] );
	
					if ( $template_slug ) {
						$template = WPRM_Template_Manager::get_template_by_slug( $template_slug );
					}
	
					if ( ! $template ) {
						$recipe = WPRM_Recipe_Manager::get_recipe( $recipe_id );
						$type = $recipe ? $recipe->type() : 'food';

						$template = WPRM_Template_Manager::get_template_by_type( 'snippet', $type );
					}

					if ( $template ) {
						// Add to used templates.
						WPRM_Template_Manager::add_used_template( $template );

						$output = '<div class="wprm-recipe wprm-recipe-snippet wprm-recipe-template-' . esc_attr( $template['slug'] ) . '">' . do_shortcode( $template['html'] ) . '</div>';
						return apply_filters( 'wprm_recipe_snippet_shortcode_output', $output, $atts, $recipe_id, $template );
					}
				}

				// Reset current recipe ID.
				if ( $atts['id'] ) {
					WPRM_Template_Shortcodes::set_current_recipe_id( false );
				}
			}
		}

		return '';
	}

Code file location:

wp-recipe-maker/wp-recipe-maker/includes/public/class-wprm-shortcode-snippets.php

WP Recipe Maker [wprm-recipe] Shortcode

The WP Recipe Maker shortcode is a powerful tool that allows you to display a specific recipe on your WordPress site. By using the ‘id’ attribute, you can specify the recipe you want to display. It can fetch a random recipe, the latest one, a demo, or a specific recipe by its ID. The shortcode also accommodates various viewing contexts like AMP, feed, and REST API, adjusting its output accordingly. It can return a recipe summary for excerpts or a full recipe for single views. The shortcode also handles recipe alignment and metadata output.

Shortcode: [wprm-recipe]

Parameters

Here is a list of all possible wprm-recipe shortcode parameters and attributes:

  • id – Identifier of the recipe to display.
  • align – Adjusts the alignment of the recipe.
  • template – Specifies the template to use for the recipe.

Examples and Usage

Basic example – Display a random recipe on your website using the WP Recipe Maker shortcode.

[wprm-recipe id=random /]

Advanced examples

Display the latest recipe added to your website. This shortcode will fetch the most recent recipe post and display it on your page.

[wprm-recipe id=latest /]

Show a specific recipe by its ID. Replace ‘123’ with the ID of the recipe you want to display.

[wprm-recipe id=123 /]

Align the recipe to the right of your page. This shortcode will display the recipe with an alignment to the right.

[wprm-recipe id=123 align=right /]

Display a recipe using a specific template. Replace ‘template_name’ with the name of the template you want to use.

[wprm-recipe id=123 template=template_name /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wprm-recipe] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wprm-recipe', array( __CLASS__, 'recipe_shortcode' ) );

Shortcode PHP function:

function recipe_shortcode( $atts ) {
		$atts = shortcode_atts( array(
			'id' => 'random',
			'align' => '',
			'template' => '',
		), $atts, 'wprm_recipe' );

		$recipe_template = trim( $atts['template'] );

		// Get recipe.
		if ( 'random' === $atts['id'] ) {
			$posts = get_posts( array(
				'post_type' => WPRM_POST_TYPE,
				'posts_per_page' => 1,
				'orderby' => 'rand',
			) );

			$recipe_id = isset( $posts[0] ) ? $posts[0]->ID : 0;
		} elseif ( 'latest' === $atts['id'] ) {
			$posts = get_posts(array(
				'post_type' => WPRM_POST_TYPE,
				'posts_per_page' => 1,
			));

			$recipe_id = isset( $posts[0] ) ? $posts[0]->ID : 0;
		} elseif ( 'demo' === $atts['id'] ) {
			$recipe_id = 'demo';
		} else {
			$recipe_id = intval( $atts['id'] );
		}

		$recipe = WPRM_Recipe_Manager::get_recipe( $recipe_id );

		if ( $recipe ) {			
			WPRM_Assets::load();

			// Output recipe data on page.
			add_filter( 'wprm_recipes_on_page', function( $recipes ) use ( $recipe_id ) {
				$recipes[] = $recipe_id;
				return $recipes;
			} );

			// Check type of recipe we need to output.
			if ( 0 < count( self::$shortcode_type ) ) {
				$type = end( self::$shortcode_type );
			} else {
				$type = 'single';

				if ( is_feed() ) {
					$type = 'feed';
				} elseif ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
					$type = 'amp';
					$recipe_template = ''; // Force default AMP template.
				} elseif ( isset( $GLOBALS['wp']->query_vars['rest_route'] ) && '/wp/v2/posts' === substr( $GLOBALS['wp']->query_vars['rest_route'], 0, 12 ) ) {
					$type = 'single'; // Use single template when accessing post through REST API.
				} elseif ( is_admin() ) {
					$type = 'single';
				} elseif ( is_front_page() || ! is_singular() || ! is_main_query() ) {
					$type = 'archive';
				}
			}

			// Early return recipe summary if this is for an excerpt.
			if ( 'excerpt' === $type ) {
				return $recipe->summary();
			}

			// Output full snippet or recipe template.
			$align_class = '';
			if ( isset( $atts['align'] ) && $atts['align'] ) {
				$align_class = ' align' . esc_attr( $atts['align'] );
			}

			if ( $recipe_template && 'snippet-' === substr( $recipe_template, 0, 8 ) ) {
				$output = '<div id="wprm-recipe-snippet-container-' . esc_attr( $recipe->id() ) . '" class="wprm-recipe-snippet-container' . esc_attr( $align_class ) . '" data-recipe-id="' . esc_attr( $recipe->id() ) . '">';
			} else {
				$output = '<div id="wprm-recipe-container-' . esc_attr( $recipe->id() ) . '" class="wprm-recipe-container' . esc_attr( $align_class ) . '" data-recipe-id="' . esc_attr( $recipe->id() ) . '" data-servings="' . esc_attr( $recipe->servings() ) . '">';
			}

			if ( 'amp' === $type || 'single' === $type ) {
				if ( 'recipe' === WPRM_Settings::get( 'metadata_location' ) && ! WPRM_Metadata::use_yoast_seo_integration() && WPRM_Metadata::should_output_metadata_for( $recipe->id() ) ) {
					$metadata_output = WPRM_Metadata::get_metadata_output( $recipe );

					if ( $metadata_output ) {
						$output .= $metadata_output;
						WPRM_Metadata::outputted_metadata_for( $recipe->id() );
					}
				}
			}

			$output .= WPRM_Template_Manager::get_template( $recipe, $type, $recipe_template );
			$output .= '</div>';
			
			return apply_filters( 'wprm_recipe_shortcode_output', $output, $recipe, $type, $recipe_template );
		} else {
			return '';
		}
	}

Code file location:

wp-recipe-maker/wp-recipe-maker/includes/public/class-wprm-shortcode.php

WP Recipe Maker [seo_recipe] Shortcode

The ‘seo_recipe’ shortcode from the WP Recipe Maker plugin generates a recipe output based on the ID provided. If the ID is incorrect or not found, it returns an empty string. It detects if the ID is from a different post type, finds the recipe in the content, or migrates from WP Ultimate Recipe if needed.

Shortcode: [seo_recipe]

Parameters

Here is a list of all possible seo_recipe shortcode parameters and attributes:

  • id – The unique identifier of the recipe post.
  • template – The specific layout or style to be used for displaying the recipe.

Examples and Usage

Basic example – The basic usage of the ‘seo_recipe’ shortcode requires the ID of the recipe post you want to display.

[seo_recipe id=123 /]

Advanced examples

Displaying a specific recipe using a custom template. The ‘template’ attribute allows you to specify a custom template for the recipe display. If the specified template does not exist, the plugin will fallback to the default template.

[seo_recipe id=123 template="custom_template" /]

Displaying a recipe that was migrated from WP Ultimate Recipe. If the recipe was migrated from WP Ultimate Recipe, the ‘_wpurp_wprm_migrated’ post meta will contain the new ID of the recipe in WP Recipe Maker. This shortcode will first try to display the recipe with the given ID, but if it doesn’t exist, it will check if there’s a migrated recipe with that ID and display it instead.

[seo_recipe id=456 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [seo_recipe] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'seo_recipe', array( __CLASS__, 'recipe_shortcode_fallback' ) );

Shortcode PHP function:

function recipe_shortcode_fallback( $atts ) {
		$atts = shortcode_atts( array(
			'id' => false,
			'template' => '',
		), $atts );

		// Prevent outputting random recipe.
		if ( false === $atts['id'] ) {
			return '';
		} else {
			if ( WPRM_POST_TYPE !== get_post_type( $atts['id'] ) ) {
				// Find recipe in content.
				$recipe_ids = WPRM_Recipe_Manager::get_recipe_ids_from_post( $atts['id'] );

				if ( $recipe_ids && isset( $recipe_ids[0] ) ) {
					$atts['id'] = $recipe_ids[0];
				} else {
					// WP Ultimate Recipe shortcode migrated?
					$migrated_id = get_post_meta( $atts['id'], '_wpurp_wprm_migrated', true );
					if ( $migrated_id ) {
						$atts['id'] = intval( $migrated_id );
					}
				}
			}

			return self::recipe_shortcode( $atts );
		}
	}

Code file location:

wp-recipe-maker/wp-recipe-maker/includes/public/class-wprm-shortcode.php

WP Recipe Maker [nutrition-label] Shortcode

The WP Recipe Maker shortcode, ‘nutrition-label’, is designed to remove existing content. When implemented, it returns an empty string, essentially erasing any content linked to it.

Shortcode: [nutrition-label]

Examples and Usage

Basic example – The shortcode ‘nutrition-label’ removes the shortcode from the output. It does not require any parameters to function.

[nutrition-label /]

Advanced examples

Even though the ‘nutrition-label’ shortcode does not require any parameters, you can still use it in combination with other shortcodes to create more advanced functionalities. Here are a few examples:

Using the shortcode to conditionally display content based on whether a specific shortcode exists or not. In this case, if the ‘nutrition-label’ shortcode is present, the ‘content’ shortcode will not be displayed.

[if shortcode_exists('nutrition-label')][content /][/if]

Using the shortcode to remove other shortcodes. In this example, the ‘nutrition-label’ shortcode is used to remove the ‘recipe’ shortcode from the output.

[nutrition-label][recipe /][/nutrition-label]

PHP Function Code

In case you have difficulties debugging what causing issues with [nutrition-label] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'nutrition-label', array( __CLASS__, 'remove_shortcode' ) );

Shortcode PHP function:

function remove_shortcode() {
		return '';
	}

Code file location:

wp-recipe-maker/wp-recipe-maker/includes/public/class-wprm-shortcode.php

Conclusion

Now that you’ve learned how to embed the WP Recipe Maker Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *