Quick Restaurant Menu Shortcodes

Below, you’ll find a detailed guide on how to add the Quick Restaurant Menu 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 Quick Restaurant Menu Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Quick Restaurant Menu Plugin and the shortcodes it provides:

Plugin Icon
Quick Restaurant Menu

"Quick Restaurant Menu is a user-friendly WordPress plugin specially designed to help restaurants create and manage their menus with ease. Perfect for fast updates and customization."

★★★★✩ (27) Active Installs: 3000+ Tested with: 6.0.6 PHP Version: false
Included Shortcodes:
  • [erm_menu]
  • [erm_menu_week]

Quick Restaurant Menu [erm_menu] Shortcode

The Quick-Restaurant-Menu shortcode is a powerful tool for displaying menus on your WordPress site. It allows customization of the menu’s appearance and content. The shortcode uses global post data to fetch and display a menu. It allows you to specify the ‘id’ of the menu, whether to show ‘thumb’ (thumbnails), the ‘price’ position, and if the price should be ‘inline’. If the post type isn’t ‘erm_menu’, it returns an empty string. The menu is then rendered using a template from the plugin’s directory.

Shortcode: [erm_menu]

Parameters

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

  • id – Unique identifier of the menu post
  • thumb – Decides if thumbnails are shown or not
  • price – Determines the position of the price
  • price_inline – Decides if price is displayed inline or not

Examples and Usage

Basic example – Display a menu with its default settings.

[erm_menu id=1 /]

Advanced examples

Display a menu without thumbnails, with price at the top and not inline.

[erm_menu id=1 thumb=no price=top price_inline=no /]

Display a menu with thumbnails, with price at the bottom and inline.

[erm_menu id=1 thumb=yes price=bottom price_inline=yes /]

Display a menu without thumbnails, with price at the bottom and not inline.

[erm_menu id=1 thumb=no price=bottom price_inline=no /]

Keep in mind that the ‘id’ attribute is mandatory and should match the id of the menu you want to display. The other attributes are optional and can be used to customize the appearance of the menu.

PHP Function Code

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

Shortcode line:

add_shortcode( 'erm_menu', 'erm_shortcode_menu' );

Shortcode PHP function:

function erm_shortcode_menu( $atts, $content = null ) {

	global $post;
	$post_id = is_object( $post ) ? $post->ID : 0;

	$atts = shortcode_atts( array(
		'id' 	        => $post_id,
		'thumb'         => 'yes',
		'price'         => 'top',
		'price_inline'  => 'yes'
	), $atts );

	$post_id = $atts['id']; // I only need this for the template
	$show_thumbnails = $atts['thumb'] == 'yes' ? true : false;
	$price_position = $atts['price'];
	$price_inline = $atts['price_inline'] == 'yes' ? true : false;

	if ( get_post_type( $post_id ) != 'erm_menu' ) { return ''; }

	// Template
	ob_start();
	include ERM_PLUGIN_DIR . 'templates/menu.php';
	$html = ob_get_clean();

	return $html;
}

Code file location:

quick-restaurant-menu/quick-restaurant-menu/includes/shortcodes.php

Quick Restaurant Menu [erm_menu_week] Shortcode

The Quick-Restaurant-Menu plugin shortcode, ‘erm_menu_week’, dynamically displays a weekly menu based on set rules. The shortcode fetches the current day and time, checks against the rules set in the ‘erm_week_rules’ meta field for the ‘erm_menu_week’ post type. If the current day and time fall within the specified range, the menu for the day is displayed. If not, it returns an empty string.

Shortcode: [erm_menu_week]

Parameters

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

  • id – Unique identifier of the weekly menu post.
  • thumb – Determines if thumbnails are displayed, values: ‘yes’ or ‘no’.
  • price – Determines the position of the price, values: ‘top’, ‘bottom’ or ‘hidden’.

Examples and Usage

Basic example – The shortcode displays the weekly menu of the restaurant, by referencing the post ID.

[erm_menu_week id=1 /]

Advanced examples

The shortcode displays the weekly menu with the thumbnail of the dishes and the price positioned at the top.

[erm_menu_week id=1 thumb='yes' price='top' /]

The shortcode displays the weekly menu without the thumbnail of the dishes and with the price positioned at the bottom.

[erm_menu_week id=1 thumb='no' price='bottom' /]

The shortcode displays the weekly menu using the post ID, with the thumbnail of the dishes and the price positioned at the top. If the post type is not ‘erm_menu_week’, or if there are no rules set for the weekly menu, the shortcode will return an empty string.

[erm_menu_week id=1 thumb='yes' price='top' /]

These examples demonstrate the versatility of the ‘erm_menu_week’ shortcode in displaying the weekly menu according to specific parameters.

PHP Function Code

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

Shortcode line:

add_shortcode( 'erm_menu_week', 'erm_shortcode_menu_week' );

Shortcode PHP function:

function erm_shortcode_menu_week( $atts, $content = null ){

	global $post;
	$post_id = is_object( $post ) ? $post->ID : 0;

	$atts = shortcode_atts( array(
		'id' 	        => $post_id,
		'thumb'         => 'yes',
		'price'         => 'top'
	), $atts, 'erm_menu' );

	$post_id = $atts['id'];

	if ( get_post_type( $post_id ) != 'erm_menu_week' ) { return; }

	$rules = get_post_meta( $post_id, 'erm_week_rules', true );
	if (empty($rules)) { return; }

	// Get today
	$now = current_time('timestamp',0);
	$now_day = current_time('w',0); // 0-6 0=sunday
	//echo '<pre>NOW: '; print_r( $now ); echo '</pre>';
	//echo '<pre>NOW DAY: '; print_r( $now_day ); echo '</pre>';
	//echo '<pre>'; print_r( current_time('mysql',0) ); echo '</pre>';

	//$blogtime = current_time( 'mysql',0);
	//list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '/([^0-9])/', $blogtime );
	$hour = current_time('H',0);
	$minute = current_time('i',0);
	$day_minutes = 60*intval($hour)+intval($minute);
	//echo '<pre>HOUR: '; print_r( $hour ); echo '</pre>';
	//echo '<pre>MINUTES: '; print_r( $minute ); echo '</pre>';
	//echo '<pre>DAY MINUTES: '; print_r( $day_minutes ); echo '</pre>';

	// Check each rule
	foreach( $rules as $rule ) {
		//echo '<pre>RULE: '; print_r( $rule ); echo '</pre>';
		// Check if day is included
		$days_rule = array();
		$index = 0;
		foreach($rule['week'] as $day) {
			if ($day === 'true' ) {
				$days_rule[] = $index;
			}
			$index++;
		}
		if ( !in_array($now_day,$days_rule) ) {
			continue;
		}

		// Check hours
		list( $hour1, $min1 ) = preg_split('/:/', $rule['begin']);
		list( $hour2, $min2 ) = preg_split('/:/', $rule['end']);
		$minutes_begin = 60*intval($hour1)+intval($min1);
		$minutes_end = 60*intval($hour2)+intval($min2);


		if ( $minutes_begin<=$day_minutes && $minutes_end>=$day_minutes ) {
			return do_shortcode('[erm_menu id='.$rule['menu_id'].' thumb='.$atts['thumb'].' price='.$atts['price'].']');
		}
	}

	return '';
}

Code file location:

quick-restaurant-menu/quick-restaurant-menu/includes/shortcodes.php

Conclusion

Now that you’ve learned how to embed the Quick Restaurant Menu 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 *