Social Reviews & Recommendations Shortcode

Below, you’ll find a detailed guide on how to add the Social Reviews & Recommendations 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 Social Reviews & Recommendations Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Social Reviews & Recommendations Plugin and the shortcodes it provides:

Plugin Icon
Social Reviews & Recommendations

"Social Reviews & Recommendations is a WordPress plugin. Use it to showcase your Facebook reviews and customer testimonials directly on your site, enhancing credibility and trust."

★★★★☆ (312) Active Installs: 10000+ Tested with: 6.2.3 PHP Version: false
Included Shortcodes:
  • [fbrev]

Social Reviews & Recommendations [fbrev] Shortcode

The FB Reviews Widget shortcode is a tool that fetches and displays Facebook reviews. It verifies if the widget is enabled and if the ‘Fb_Reviews_Widget’ class exists. It requires a ‘page_id’ attribute. If not provided, an error message is displayed. The shortcode calls the ‘fbrev_api_rating’ function to get the reviews data. If successful, it displays the reviews and overall star rating. Shortcode: [fbrev]

Shortcode: [fbrev]

Parameters

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

  • page_id – Facebook page ID to display reviews from.
  • page_access_token – Access token for accessing the Facebook page.
  • cache – Time period in seconds to cache reviews data.
  • api_ratings_limit – Limit for the number of API ratings to fetch.
  • show_success_api – Display successful API call message if set.
  • rating_count – Number of ratings to display.
  • title – Title to display above the reviews.

Examples and Usage

Basic example – Display Facebook reviews on your WordPress page using the ‘fbrev’ shortcode. This example uses the ‘page_id’ attribute to specify the Facebook page from where the reviews will be fetched.

[fbrev page_id="your_facebook_page_id" /]

Advanced examples

Display Facebook reviews with a custom title by using the ‘title’ attribute. This will add a title to the reviews section on your WordPress page.

[fbrev page_id="your_facebook_page_id" title="Your Custom Title" /]

Control the number of reviews displayed on your WordPress page with the ‘api_ratings_limit’ attribute. This example shows how to limit the number of displayed reviews to 5.

[fbrev page_id="your_facebook_page_id" api_ratings_limit=5 /]

Display Facebook reviews and include the overall Facebook page rating by using the ‘show_success_api’ attribute. This will include an overall rating score from Facebook along with the individual reviews.

[fbrev page_id="your_facebook_page_id" show_success_api=true /]

PHP Function Code

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

Shortcode line:

add_shortcode("fbrev", "fbrev_shortcode");

Shortcode PHP function:

function fbrev_shortcode($atts) {
    global $wpdb;

    if (!fbrev_enabled()) return '';
    if (!class_exists('Fb_Reviews_Widget')) return '';

    $shortcode_atts = array();
    foreach (Fb_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($page_id)) {
        ?>
        <div class="fbrev-error" style="padding:10px;color:#b94a48;background-color:#f2dede;border-color:#eed3d7;max-width:200px;">
            <?php echo fbrev_i('<b>Facebook Reviews Widget</b>: required attribute page_id is not defined'); ?>
        </div>
        <?php
    } else {
        $response = fbrev_api_rating($page_id, $page_access_token, $shortcode_atts, md5($page_access_token), $cache, $api_ratings_limit, $show_success_api);
        $response_data = $response['data'];
        $response_json = rplg_json_decode($response_data);
        if (isset($response_json->ratings) && isset($response_json->ratings->data)) {
            $reviews = $response_json->ratings->data;
            if (isset($response_json->overall_star_rating)) {
                $facebook_rating = number_format((float)$response_json->overall_star_rating, 1, '.', '');
            }
            if (isset($response_json->rating_count) && $response_json->rating_count > 0) {
                $facebook_count = $response_json->rating_count;
            }
            if (isset($rating_count) && $rating_count > 0) {
                $facebook_count += $rating_count;
            }
            if ($title) { ?><h2 class="fbrev-widget-title widget-title"><?php echo $title; ?></h2><?php }
            include(dirname(__FILE__) . '/fbrev-reviews.php');
        } else {
            ?>
            <div class="fbrev-error" style="padding:10px;color:#B94A48;background-color:#F2DEDE;border-color:#EED3D7;">
                <?php echo fbrev_i('Facebook API Error: ') . $response_data . fbrev_i('<br><b>Reconnecting to Facebook may fix the issue.</b>'); ?>
            </div>
            <?php
        }
    }
    return preg_replace('/[\n\r]/', '', ob_get_clean());
}

Code file location:

fb-reviews-widget/fb-reviews-widget/fbrev.php

Conclusion

Now that you’ve learned how to embed the Social Reviews & Recommendations 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.

Comments

Leave a Reply

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