Below, you’ll find a detailed guide on how to add the Tlp Food 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 Tlp Food Menu Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Tlp Food Menu Plugin and the shortcodes it provides:
"Food Menu – Restaurant Menu & Online Ordering for WooCommerce is a versatile plugin that adds seamless online food ordering functionality to your WooCommerce storefront. Enhance user experience with tlp-food-menu."
- [foodmenu]
- [foodmenu-single]
Tlp Food Menu [foodmenu] Shortcode
The tlp-food-menu shortcode is designed to render a food menu on a WordPress site. It dynamically fetches the menu data based on the shortcode attributes and displays it in a user-friendly format.
Shortcode: [foodmenu]
Parameters
Here is a list of all possible foodmenu shortcode parameters and attributes:
id
– A unique number that identifies the specific food menu.
Examples and Usage
Basic example – Displaying a food menu by referencing its ID
[foodmenu id=1 /]
Advanced examples
Displaying a food menu by referencing its ID and including additional attributes like layout and pagination.
[foodmenu id=1 layout="grid" pagination="true" /]
Using the shortcode to display a food menu by referencing its ID and specifying the number of columns for desktop, tablet, and mobile view respectively.
[foodmenu id=1 dCols=3 tCols=2 mCols=1 /]
Using the shortcode to display a food menu by referencing its ID and specifying the animation, image position, and link type.
[foodmenu id=1 animation="zoom_in" imagePosition="top" linkType="newpage" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [foodmenu]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'foodmenu', [ $this, 'render' ] );
Shortcode PHP function:
function render( $atts ) {
$scID = isset( $atts['id'] ) ? absint( $atts['id'] ) : null;
if ( ! $scID && is_null( get_post( $scID ) ) ) {
return;
}
if ( 0 === $scID ) {
return;
}
$this->scId = $scID;
$scMeta = get_post_meta( $scID );
$rand = absint( wp_rand() );
$layoutID = 'fmp-container-' . $rand;
$html = null;
$containerAttr = null;
$masonryG = null;
$preLoader = null;
$preLoaderHtml = null;
$args = [];
$arg = [];
$itemsOnMobile = '';
$metas = RenderHelpers::metaScBuilder( $scMeta );
$arg = RenderHelpers::argBuilder( $scID, $metas, $scMeta );
$layout = $metas['layout'];
$gridType = $metas['gridType'];
$animation = isset( $metas['animation'] ) ? $metas['animation'] : 'zoom_in';
$imagePosition = isset( $metas['imagePosition'] ) ? $metas['imagePosition'] : 'top';
$pagination = $metas['pagination'];
$parentClass = $metas['parentClass'];
$linkType = isset( $metas['linkType'] ) ? $metas['linkType'] : 'newpage';
$hasModal = 'popup' === $linkType ? true : false;
$hasIcon = $metas['hoverIcon'] ? true : false;
$mobileItems = ! empty( $metas['mobileItems'] ) ? $metas['mobileItems'] : array_keys( Options::fmpMobileItemFields() );
if ( ! empty( $mobileItems ) && apply_filters( 'tlp_fmp_has_multiple_meta_issue', false ) ) {
$mobileItems = unserialize( $mobileItems[0] );
}
if ( ! empty( $mobileItems ) && is_array( $mobileItems ) ) {
foreach ( $mobileItems as $mobileItem ) {
$itemsOnMobile .= ' has-mobile-' . $mobileItem;
}
}
if ( ! in_array( $layout, array_keys( Options::scLayouts() ), true ) ) {
$layout = 'layout-free';
}
$isIsotope = preg_match( '/isotope/', $layout );
$isCarousel = preg_match( '/carousel/', $layout );
$isCat = preg_match( '/grid-by-cat/', $layout );
$dCol = 0 === $metas['dCols'] ? RenderHelpers::defaultColumns( $layout ) : $metas['dCols'];
$tCol = 0 === $metas['tCols'] ? 2 : $metas['tCols'];
$mCol = 0 === $metas['mCols'] ? 1 : $metas['mCols'];
$containerAttr .= 'data-sc-id="' . absint( $scID ) . '" data-layout="' . esc_attr( $layout ) . '" data-desktop-col="' . absint( $dCol ) . '" data-tab-col="' . absint( $tCol ) . '" data-mobile-col="' . absint( $mCol ) . '"';
if ( 'even' === $gridType ) {
$masonryG = ' fmp-even';
} elseif ( 'masonry' === $gridType ) {
$masonryG = ' fmp-masonry';
}
if ( $isCarousel ) {
$masonryG = ' fmp-even';
}
$settings = get_option( TLPFoodMenu()->options['settings'] );
$enablePreloader = isset( $settings['fmp_preloader'] ) ? $settings['fmp_preloader'] : true;
if ( $enablePreloader ) {
$preLoader = ' fmp-pre-loader';
$preLoaderHtml = '<div class="fmp-loading-overlay"></div><div class="fmp-loading fmp-ball-clip-rotate"><div></div></div>';
if ( $isCarousel || $isIsotope ) {
$preLoaderHtml = '<div class="fmp-loading-overlay full-op"></div><div class="fmp-loading fmp-ball-clip-rotate"><div></div></div>';
}
}
$containerClass = 'fmp-container-fluid fmp-wrapper fmp';
$containerClass .= ! empty( $animation ) ? ' fmp-hover-' . $animation : ' fmp-hover-zoom_in';
$containerClass .= ! empty( $imagePosition ) ? ' fmp-image-' . $imagePosition : ' fmp-image-top';
$containerClass .= ! empty( $imageShape ) ? ' fmp-image-' . $imageShape : ' fmp-img-normal';
$containerClass .= ! empty( $itemsOnMobile ) ? $itemsOnMobile : '';
$containerClass .= $hasIcon ? ' has-hover-icon' : ' no-hover-icon';
if ( ! $isCat || 'grid-by-cat1' === $layout || 'grid-by-cat2' === $layout ) {
$rowClass = 'fmp-row fmp-content-loader fmp-' . $layout . $masonryG . $preLoader;
} else {
$rowClass = 'fmp-row fmp-content-loader fmp-' . $layout . $preLoader;
}
$rowClass = apply_filters( 'rt_fm_row_class', $rowClass, $metas );
$html .= RenderHelpers::layoutStyle( $layoutID, $scMeta );
$html .= '<div class="' . esc_attr( $containerClass ) . ' ' . esc_attr( $parentClass ) . '" id="' . esc_attr( $layoutID ) . '" ' . $containerAttr . '>';
$args = ( new QueryArgs() )->buildArgs( $scID, $metas, $isCarousel );
if ( $isCat ) {
$html .= '<div data-title="' . esc_html__( 'Loading ...', 'tlp-food-menu' ) . '" class="' . esc_attr( $rowClass ) . '">';
$html .= $this->renderCategoryLayouts( $metas, $scMeta, $args, $arg );
$html .= $preLoaderHtml;
$html .= '</div>';
} else {
$fmpQuery = new WP_Query( $args );
if ( $fmpQuery->have_posts() ) {
$html .= '<div data-title="' . esc_html__( 'Loading ...', 'tlp-food-menu' ) . '" class="' . esc_attr( $rowClass ) . '">';
ob_start();
do_action( 'rt_fm_sc_before_loop', $scMeta, $rand );
$html .= ob_get_contents();
ob_end_clean();
while ( $fmpQuery->have_posts() ) {
$fmpQuery->the_post();
// Loop Args.
$arg = RenderHelpers::loopArgBuilder( $arg, $metas, $scMeta, get_the_ID() );
// Render Layout.
$html .= Fns::render( 'layouts/' . $layout, $arg, true );
}
ob_start();
do_action( 'rt_fm_sc_after_loop', $scMeta );
$html .= ob_get_contents();
ob_end_clean();
$html .= $preLoaderHtml;
$html .= '</div>';
if ( $pagination && ! $isCarousel ) {
$renderPagination = RenderHelpers::renderPagination(
$fmpQuery,
$metas,
$scMeta['fmp_limit'][0],
$scMeta['fmp_posts_per_page'][0],
$scID,
$metas['posts_loading_type']
);
$html .= '<div class="fmp-col-xs-12">';
$html .= '<div class="fmp-utility">';
if ( 'pagination' === $metas['posts_loading_type'] || 'pagination_ajax' === $metas['posts_loading_type'] ) {
$html .= $renderPagination;
} elseif ( 'load_more' === $metas['posts_loading_type'] || 'load_on_scroll' === $metas['posts_loading_type'] ) {
if ( TLPFoodMenu()->has_pro() ) {
$html .= apply_filters( 'rtfm_pagination', $scID, $metas['posts_loading_type'], $metas['load_more_text'], $fmpQuery );
}
}
$html .= '</div>';
$html .= '</div>';
}
wp_reset_postdata();
} else {
$html .= '<p>' . esc_html__( 'No posts found.', 'tlp-food-menu' ) . '</p>';
}
}
$html .= '</div>';
$isIsotope = ' fmp-masonry' === $masonryG ? true : $isIsotope;
$scriptGenerator = [];
$scriptGenerator['scId'] = $scID;
$scriptGenerator['layout'] = $layoutID;
$scriptGenerator['rand'] = $rand;
$scriptGenerator['isIsotope'] = $isIsotope;
$scriptGenerator['isCarousel'] = $isCarousel;
$scriptGenerator['hasPagination'] = $pagination;
$scriptGenerator['hasModal'] = $hasModal;
add_action(
'wp_footer',
static function () use ( $scriptGenerator ) {
RenderHelpers::registerScripts( $scriptGenerator );
}
);
return $html;
}
Code file location:
tlp-food-menu/tlp-food-menu/app/Controllers/Frontend/Shortcode.php
Tlp Food Menu [foodmenu-single] Shortcode
The TLP Food Menu plugin shortcode, ‘foodmenu-single’, is designed to render a single food item on your webpage. The shortcode takes an ‘id’ attribute, representing the specific food item to be displayed. The function ‘renderSingle’ is responsible for generating the HTML output, which currently returns null, indicating that the HTML structure is yet to be defined.
Shortcode: [foodmenu-single]
Parameters
Here is a list of all possible foodmenu-single shortcode parameters and attributes:
id
– Specifies the unique identifier of the food menu item
Examples and Usage
Basic example – A simple usage of the ‘foodmenu-single’ shortcode to render a single food menu by its ID.
[foodmenu-single id=1 /]
Advanced examples
Utilizing the ‘foodmenu-single’ shortcode with multiple parameters. This example demonstrates how to use the shortcode with two IDs, rendering two food menus simultaneously.
[foodmenu-single id="1,2" /]
Another advanced example of the ‘foodmenu-single’ shortcode, this time utilizing a range of IDs. This will render all food menus within the specified ID range.
[foodmenu-single id="1-5" /]
Please note that the above examples assume that you have food menus with the corresponding IDs in your WordPress database. If a specified ID does not exist, the shortcode will not render anything for that ID.
PHP Function Code
In case you have difficulties debugging what causing issues with [foodmenu-single]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'foodmenu-single', [ $this, 'renderSingle' ] );
Shortcode PHP function:
function renderSingle( $atts ) {
$html = null;
$atts = shortcode_atts(
[
'id' => null,
],
$atts,
'foodmenu-single'
);
return $html;
}
Code file location:
tlp-food-menu/tlp-food-menu/app/Controllers/Frontend/Shortcode.php
Conclusion
Now that you’ve learned how to embed the Tlp Food 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.
Leave a Reply