Code

Google Review Star Schema

Add Google review stars to your Webflow site via this small Javascript script and CSS. This allows your Webflow site to display star ratings in Google's search results.

Google Review Star Schema preview

Add Google review stars to your Webflow site via this small Javascript script and CSS. This allows your Webflow site to display star ratings in Google's search results.

How to add it

  1. Create stars on list and template pages with HTML and CSS code snippets
  2. Add the HTML for the dynamic stars based on the CMS rating number
  3. Ensure each review is listed on the list page
  4. Update the Javascript code with relevant CMS/detail information from your site

The code

Javascript
                          var reviewRatingsSum = 0;
    var reviewCount = $(".review-counter_stars").length;

    $(".review-counter_stars").each(function() {
        reviewRatingsSum += parseInt($(this).html());
    });

    var reviewAverageMath = reviewRatingsSum / reviewCount;
    var reviewAverage = reviewAverageMath.toFixed(1);

    $("#reviewAg").text(function() {
        return JSON.stringify({

            "@context": "https://schema.org/",
            "@type": "AggregateRating",
            "itemReviewed": {
                "@type": "SoftwareApplication",
                "image": "https://cdn.prod.website-files.com/606e5a8c5c2aca44ea4a8dbc/607ef114a8e80b58e507ad5a_Aalto%20OG%20Image.jpg",
                "name": "Aalto",
                "applicationCategory": "HomeApplication",
                "aggregateRating": {
                  "@type": "AggregateRating",
                  "ratingValue": reviewAverage,
                  "ratingCount": reviewCount
                },
                "offers": {
                		"priceCurrency": "USD",
                    "@type": "Offer",
                    "price": "0"
                }
            },
            "ratingValue": reviewAverage,
            "bestRating": "5.0",
            "ratingCount": reviewCount

        });
    });



                    
CSS
                      <style>
.review-stars {
    --percent: calc(var(--rating) / 5 * 100%);
    display: block;
    font-size: 20px;
    font-family: Times;
    line-height: 1;
    margin-top: 4px;
  }
  
  .review-stars::before {
    content: "★★★★★";
    letter-spacing: 2px;
    background: linear-gradient(90deg, #e87949 var(--percent), #fad2c1 var(--percent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
</style>

                    
HTML
                      <div class="review-stars" style="--rating: {{rating}};"></div>
<div class="sr-only"><span class="review-counter_stars">{{rating}}</span> star review rating</div>

                    

Browse similar code snippets

More from Corey Moen

Profile →

Similar code snippets

All code snippets →