Below, you’ll find a detailed guide on how to add the Widget for Yelp Reviews Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Widget for Yelp Reviews Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Widget for Yelp Reviews Plugin and the shortcodes it provides:
"Widget for Yelp Reviews is a practical WordPress plugin that allows users to seamlessly integrate and display Yelp business reviews on their website. Enhance credibility and trust with this easy-to-use tool."
- [yrw]
Widget for Yelp Reviews [yrw] Shortcode
The Yelp Reviews Widget (YRW) shortcode is a PHP function that displays Yelp business reviews on your WordPress site. It fetches data from Yelp’s API based on a provided business ID. If the business ID is missing, it displays an error message. Otherwise, it includes the ‘yrw-reviews.php’ file, which is responsible for fetching and displaying the reviews.
Shortcode: [yrw]
Parameters
Here is a list of all possible yrw shortcode parameters and attributes:
Based on the provided code, there is only one parameter that is clearly defined:
business_id
– the unique identifier for the Yelp business
However, the code suggests the possibility of additional parameters that are dynamically created based on the field values in the Yelp_Reviews_Widget class. These parameters are not clearly defined in the provided code and would depend on the specific instance of the Yelp_Reviews_Widget class.
Examples and Usage
Basic example – Show Yelp reviews for a specific business by using the business_id attribute in the shortcode.
[yrw business_id="your-business-id" /]
Advanced examples
Display Yelp reviews for a business with specific settings. Here we are setting the ‘disable_user_link’ attribute to ‘true’, which means the user’s Yelp profile will not be linked in the review. We’re also setting the ‘max_width’ attribute to ‘500’, which means the widget will not be wider than 500 pixels.
[yrw business_id="your-business-id" disable_user_link="true" max_width="500" /]
Here’s another example where we are setting the ‘max_width’ attribute to ‘300’ and the ‘max_height’ attribute to ‘500’. This means the widget will not be wider than 300 pixels and not taller than 500 pixels. We’re also setting the ‘disable_avatar’ attribute to ‘true’, which means the user’s avatar will not be displayed in the review.
[yrw business_id="your-business-id" max_width="300" max_height="500" disable_avatar="true" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [yrw]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode("yrw", "yrw_shortcode");
Shortcode PHP function:
function yrw_shortcode($atts) {
global $wpdb;
if (!yrw_enabled()) return '';
if (!class_exists('Yelp_Reviews_Widget')) return '';
$shortcode_atts = array();
foreach (Yelp_Reviews_Widget::$widget_fields as $field => $value) {
$shortcode_atts[$field] = isset($atts[$field]) ? strip_tags(stripslashes($atts[$field])) : '';
}
foreach ($shortcode_atts as $variable => $value) {
${$variable} = esc_attr($shortcode_atts[$variable]);
}
ob_start();
if (empty($business_id)) {
?>
<div class="yrw-error" style="padding:10px;color:#b94a48;background-color:#f2dede;border-color:#eed3d7;max-width:200px;">
<?php echo yrw_i('<b>Google Reviews Business</b>: required attribute business_id is not defined'); ?>
</div>
<?php
} else {
include(dirname(__FILE__) . '/yrw-reviews.php');
}
return preg_replace('/[\n\r]/', '', ob_get_clean());
}
Code file location:
widget-yelp-reviews/widget-yelp-reviews/yrw.php
Conclusion
Now that you’ve learned how to embed the Widget for Yelp Reviews Plugin shortcode, 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