How to Remove Structured Data Errors for Reviews

Here on WP-Tweaks, I personally review a lot of web hosting products, but recently I decided to accept user reviews as well. This required a new kind of structured data – “aggregateRating” field, and so I needed a plugin to do this for me automatically. Unfortunately, I wasn’t able to remove structured data errors for any of them. They were all missing some piece of structured data or the other.

Here are some commonly missed pieces:

Errors in Google's Structured Data Testing Tool.
Structured Data Errors for Review

Some of the common messages are:

  1. “The brand field is recommended. Please provide a value of available”
  2. “The offers field is recommended. Please provide a value of available”
  3. “The sku field is recommended. Please provide a value of available”

It’s very frustrating to find a plugin you like, but which simply doesn’t include the necessary structured data that generates 0 errors in the testing tool.

But I finally found the “Site Reviews” plugin, which lets you use filters to customize the output of structured data and add missing fields. You can see on my NameHero reviews page, how I’ve managed to integrate aggregate ratings with error free structured data.

Update: Now you can use the AI chatbot ChatGPT to generate the product review structured data schema for you!

Here’s how to do it.

Step 1: Install Site Reviews and Display the Ratings with Schema

The Site Reviews plugin allows you to associate reviews with a particular post or page. It has Gutenberg blocks available for this purpose and it makes it easy to display the latest reviews, the aggregate rating summary and the submit form.

For the “latest reviews” block, enable the schema as shown here:

Enable the Site Reviews Schema
Enable the Site Reviews Schema

You should only enable the schema for one block, and not the summary. Now when you save your post and submit it to the Google structured data testing tool, you should get a bunch of errors as shown in the first screenshot.

Step 2: Add Missing Structured Data as Custom Fields

So let’s say that “brand” is missing for you, and you want to add this piece of structured data to the schema. Scroll down to the bottom of your post to the “custom fields” section and add a “name” and “value” representing the brand name you want as shown here:

Add Structured Data to the Custom Fields
Use Custom Fields to Add New Structured Data

Do this as many times as you need. Make sure to create a unique “Name” field for each custom data you want to add. Some of these might be nested within others, and that’s fine. For now, just add the information. In the screenshot above, I’m adding the data for “offers”.

Step 3: Output the Structured Data with a Filter

Now here’s the real magic. The Site Reviews plugin exposes a filter that allows you to change the output of the structured data. To do this, you’ll need to add a code snippet to your functions.php file or to your custom code plugin. If you don’t know how to do this, here’s a tutorial on how to add code snippets to WordPress:

The code takes the following steps:

  1. Extract the custom fields data and save the values in variables
  2. Add values to the “schema” array
  3. Return the modified schema array

For me, this is what the code looks like:

add_filter( 'site-reviews/schema/Product', function( $schema ) { 

    $postId = get_the_ID();

    $sku = get_post_meta( $postId, 'schema_sku', true );
    $brand = get_post_meta( $postId, 'schema_brand', true );
    $image = get_post_meta( $postId, 'schema_image', true );
    $sku = get_post_meta( $postId, 'schema_sku', true );
    $mpn = get_post_meta( $postId, 'schema_mpn', true );

    $offers_url = get_post_meta( $postId, 'offers_url', true );
    $offers_priceCurrency = get_post_meta( $postId, 'offers_priceCurrency', true );
    $offers_price = get_post_meta( $postId, 'offers_price', true );
    $offers_itemCondition = get_post_meta( $postId, 'offers_itemCondition', true );
    $offers_availability = get_post_meta( $postId, 'offers_availability', true );
    $offers_seller_name = get_post_meta( $postId, 'offers_seller_name', true );
    $offers_priceValidUntil = get_post_meta( $postId, 'offers_priceValidUntil', true );


    $schema['offers'] = [
        '@type' => 'Offer',
        'url' => $offers_url,
        'priceCurrency' => $offers_priceCurrency,
        'price' => $offers_price,
        'itemCondition' => $offers_itemCondition,
        'availability' => $offers_availability,
        'seller' => [
            '@type' => 'Organization',
            'name' => $offers_seller_name,
        ],
        'priceValidUntil' => $offers_priceValidUntil,
    ];

    $schema['sku'] = get_post_meta( $postId, 'schema_sku', true );
    $schema['brand'] = get_post_meta( $postId, 'schema_brand', true );
    $schema['image'] = get_post_meta( $postId, 'schema_image', true );
    $schema['sku'] = get_post_meta( $postId, 'schema_sku', true );
    $schema['mpn'] = get_post_meta( $postId, 'schema_mpn', true );
    $schema['name'] = get_post_meta( $postId, 'schema_name', true );
    $schema['description'] = get_post_meta( $postId, 'schema_description', true );

    return $schema;
}); 

You’ll see that this also allows me to create nested structures. For example, in the “offers” schema, I have a nested structure called “seller” with the seller name. All I have to do is create a new “offers” value and assign an array or a nested array of values to it!

Play around a bit with this and save your changes. Finally, you can see in the screenshot below, that I’ve removed all structured data errors:

Remove structured data warnings
Structured Data Warnings Gone!

I like the Site Reviews solution because it gives us the flexibility to change the schema as we see fit. Google is always coming out with changes that can mess up individual plugins that hard code their schema output and don’t give us a way to modify it. With filters like this, the Site Reviews plugin is the best option in my opinion!

Bottom Line

It can be very frustrating to get structured data errors from a review plugin you like. But with Site Reviews, you can customize the output schema and make it whatever you want programmatically. It’s the only complete solution I’ve found so far!

About Bhagwad Park

I've been writing about web hosting and WordPress tutorials since 2008. I also create tutorials on Linux server administration, and have a ton of experience with web hosting products. Contact me via e-mail!

Speak Your Mind

*

WP-Tweaks