JAVASCRIPTseobeginner
Review and Aggregate Rating Schema Markup
Add Review and AggregateRating structured data for star ratings in Google search results
Faisal Yaqoob
December 28, 2025
#review#rating#schema#seo#structured-data#json-ld#rich-snippets#google#stars
Code
javascript
1 const productWithReviews = { 2 "@context": "https://schema.org", 3 "@type": "Product", 4 "name": "WordPress Speed Optimization Plugin", 5 "description": "All-in-one performance plugin that handles caching, image optimization, and Core Web Vitals improvements.", 6 "image": "https://yoursite.com/images/speed-plugin.jpg", 7 "brand": { 8 "@type": "Brand", 9 "name": "Your Brand" 10 }, 11 "sku": "WP-SPEED-PRO", 12 "offers": { 13 "@type": "Offer", 14 "url": "https://yoursite.com/plugins/speed-pro", 15 "priceCurrency": "USD", 16 "price": "49.00", 17 "availability": "https://schema.org/InStock" 18 }, 19 "aggregateRating": { 20 "@type": "AggregateRating", 21 "ratingValue": "4.8", 22 "bestRating": "5", 23 "worstRating": "1", 24 "ratingCount": "256", 25 "reviewCount": "189" 26 }, 27 "review": [ 28 { 29 "@type": "Review", 30 "author": { 31 "@type": "Person", 32 "name": "Sarah Johnson" 33 }, 34 "datePublished": "2025-12-10", 35 "reviewBody": "This plugin improved my PageSpeed score from 45 to 92. The caching and image optimization features are incredible.", 36 "reviewRating": { 37 "@type": "Rating", 38 "ratingValue": "5", 39 "bestRating": "5" 40 } 41 }, 42 { 43 "@type": "Review", 44 "author": { 45 "@type": "Person", 46 "name": "Mike Chen" 47 }, 48 "datePublished": "2025-11-28", 49 "reviewBody": "Great plugin with excellent support. Setup took less than 5 minutes and my site loads noticeably faster.", 50 "reviewRating": { 51 "@type": "Rating", 52 "ratingValue": "5", 53 "bestRating": "5" 54 } 55 }, 56 { 57 "@type": "Review", 58 "author": { 59 "@type": "Person", 60 "name": "Emma Williams" 61 }, 62 "datePublished": "2025-11-15", 63 "reviewBody": "Solid performance improvements. Would love to see more CDN integration options in future updates.", 64 "reviewRating": { 65 "@type": "Rating", 66 "ratingValue": "4", 67 "bestRating": "5" 68 } 69 } 70 ] 71 };
Review and Aggregate Rating Schema Markup
Add Review and AggregateRating structured data to display star ratings in Google search results. Rating stars increase click-through rates and build trust. This markup works for products, services, businesses, courses, and recipes.
Product with Reviews
const productWithReviews = {
"@context": "https://schema.org",
"@type": "Product",
"name": "WordPress Speed Optimization Plugin",
"description": "All-in-one performance plugin that handles caching, image optimization, and Core Web Vitals improvements.",
"image": "https://yoursite.com/images/speed-plugin.jpg",
"brand": {
"@type": "Brand",
"name": "Your Brand"
},
"sku": "WP-SPEED-PRO",
"offers": {
"@type": "Offer",
"url": "https://yoursite.com/plugins/speed-pro",
"priceCurrency": "USD",
"price": "49.00",
"availability": "https://schema.org/InStock"
},
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "4.8",
"bestRating": "5",
"worstRating": "1",
"ratingCount": "256",
"reviewCount": "189"
},
"review": [
{
"@type": "Review",
"author": {
"@type": "Person",
"name": "Sarah Johnson"
},
"datePublished": "2025-12-10",
"reviewBody": "This plugin improved my PageSpeed score from 45 to 92. The caching and image optimization features are incredible.",
"reviewRating": {
"@type": "Rating",
"ratingValue": "5",
"bestRating": "5"
}
},
{
"@type": "Review",
"author": {
"@type": "Person",
"name": "Mike Chen"
},
"datePublished": "2025-11-28",
"reviewBody": "Great plugin with excellent support. Setup took less than 5 minutes and my site loads noticeably faster.",
"reviewRating": {
"@type": "Rating",
"ratingValue": "5",
"bestRating": "5"
}
},
{
"@type": "Review",
"author": {
"@type": "Person",
"name": "Emma Williams"
},
"datePublished": "2025-11-15",
"reviewBody": "Solid performance improvements. Would love to see more CDN integration options in future updates.",
"reviewRating": {
"@type": "Rating",
"ratingValue": "4",
"bestRating": "5"
}
}
]
};
Local Business with Reviews
const businessWithReviews = {
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Your Web Agency",
"url": "https://yoursite.com",
"telephone": "+1-555-123-4567",
"address": {
"@type": "PostalAddress",
"streetAddress": "123 Main St",
"addressLocality": "New York",
"addressRegion": "NY",
"postalCode": "10001",
"addressCountry": "US"
},
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "4.9",
"bestRating": "5",
"ratingCount": "127",
"reviewCount": "98"
},
"review": [
{
"@type": "Review",
"author": {
"@type": "Person",
"name": "David Thompson"
},
"datePublished": "2025-12-01",
"reviewBody": "They rebuilt our entire e-commerce site on Shopify and the results have been amazing. Sales increased 40% in the first month.",
"reviewRating": {
"@type": "Rating",
"ratingValue": "5",
"bestRating": "5"
}
}
]
};
WordPress Review Schema Implementation
/**
* Output Review schema from WordPress comments
* Add to child theme functions.php
*/
function wp_review_schema_from_comments() {
if ( ! is_singular( 'post' ) && ! is_singular( 'product' ) ) {
return;
}
global $post;
// Get approved comments with ratings
$comments = get_comments( [
'post_id' => $post->ID,
'status' => 'approve',
'number' => 10,
] );
if ( empty( $comments ) ) {
return;
}
$reviews = [];
$ratings = [];
$has_rating = false;
foreach ( $comments as $comment ) {
$rating = get_comment_meta( $comment->comment_ID, 'rating', true );
if ( $rating ) {
$has_rating = true;
$ratings[] = (float) $rating;
$reviews[] = [
'@type' => 'Review',
'author' => [
'@type' => 'Person',
'name' => $comment->comment_author,
],
'datePublished' => date( 'Y-m-d', strtotime( $comment->comment_date ) ),
'reviewBody' => wp_strip_all_tags( $comment->comment_content ),
'reviewRating' => [
'@type' => 'Rating',
'ratingValue' => $rating,
'bestRating' => '5',
],
];
}
}
if ( ! $has_rating ) {
return;
}
$avg_rating = round( array_sum( $ratings ) / count( $ratings ), 1 );
$total_count = count( $ratings );
$schema = [
'@context' => 'https://schema.org',
'@type' => 'Product',
'name' => get_the_title(),
'description' => wp_trim_words( get_the_excerpt(), 30 ),
'image' => get_the_post_thumbnail_url( $post->ID, 'full' ),
'aggregateRating' => [
'@type' => 'AggregateRating',
'ratingValue' => $avg_rating,
'bestRating' => '5',
'worstRating' => '1',
'ratingCount' => $total_count,
'reviewCount' => $total_count,
],
'review' => $reviews,
];
echo '<script type="application/ld+json">'
. wp_json_encode( $schema, JSON_UNESCAPED_SLASHES )
. '</script>' . "\n";
}
add_action( 'wp_head', 'wp_review_schema_from_comments' );
Rating Input for WordPress Comments
/**
* Add star rating field to comment form
*/
function wp_add_rating_to_comment_form( $fields ) {
$fields['rating'] = '<div class="comment-form-rating">
<label for="rating">Rating</label>
<select name="rating" id="rating" required>
<option value="">Select rating...</option>
<option value="5">5 Stars - Excellent</option>
<option value="4">4 Stars - Very Good</option>
<option value="3">3 Stars - Good</option>
<option value="2">2 Stars - Fair</option>
<option value="1">1 Star - Poor</option>
</select>
</div>';
return $fields;
}
add_filter( 'comment_form_default_fields', 'wp_add_rating_to_comment_form' );
/**
* Save rating with comment
*/
function wp_save_comment_rating( $comment_id ) {
if ( isset( $_POST['rating'] ) && '' !== $_POST['rating'] ) {
$rating = intval( $_POST['rating'] );
if ( $rating >= 1 && $rating <= 5 ) {
add_comment_meta( $comment_id, 'rating', $rating );
}
}
}
add_action( 'comment_post', 'wp_save_comment_rating' );
Best Practices
- Only use real reviews — never fabricate reviews or ratings; Google penalizes fake reviews
- Include
datePublishedon each review for freshness signals - Use
aggregateRatingto summarize all reviews with average and count - Include
bestRatingandworstRating— required for proper rendering - Differentiate
ratingCountvsreviewCount— ratings can exist without written reviews - Attach reviews to the correct entity — Product, LocalBusiness, Course, etc.
- Display reviews visibly on the page — schema must match visible content
Features
- Star Ratings in SERP: Display yellow stars in Google search results
- Multiple Entity Types: Works with Products, Businesses, Courses, Services
- WordPress Integration: Auto-generates schema from WordPress comments
- Aggregate Rating: Calculates average from individual reviews
- Click-Through Boost: Star ratings can increase CTR by 20-30%
- Review Snippets: Individual reviews shown in search results
Related Snippets
SoftwareApplication Schema for Apps and Tools
Add SoftwareApplication structured data for apps, plugins, and SaaS tools to display ratings and pricing in Google
JAVASCRIPTseobeginner
javascriptPreview
const webAppSchema = {
"@context": "https://schema.org",
"@type": "WebApplication",
"name": "Schema Markup Generator",
...#software#app#schema+7
1/8/2026
View
HowTo Schema for Step-by-Step Guides
Add HowTo structured data for Google how-to rich results with steps, tools, materials, and estimated time
JAVASCRIPTseobeginner
javascriptPreview
const howToSchema = {
"@context": "https://schema.org",
"@type": "HowTo",
"name": "How to Set Up WordPress on a VPS Server",
...#howto#schema#seo+6
1/5/2026
View
Course Schema for Online Learning Platforms
Add Course structured data for Google course rich results with provider, duration, and pricing details
JAVASCRIPTseobeginner
javascriptPreview
const courseSchema = {
"@context": "https://schema.org",
"@type": "Course",
"name": "Complete WordPress Development Masterclass",
...#course#schema#seo+6
1/2/2026
View