Schema Error

Hey There,
For some reason on all of my blog posts that have comments, the schema testing tool returns an review schema error on the comments…

How do I fix this?

For example if you punch this page:

Into the structured data testing tool:https://search.google.com/structured-data/testing-tool

You’ll see what I mean.

It’s saying that the “REVIEW ITEM” is not available and it’s only doing it on posts that have comments.

I’d really like to get to the bottom of it so any help would be appreciated.

Thanks.

Hi,

You can try Snippet extention, you can install it via PRO > Validation

Kindly refer to the link below.

Hope this helps.

This did not help, I have already purchase a schema plugin that can add review schema etc. it’s almost like the structured data tool is classifying comment of the theme as reviews or something?

Did you see what the text gave back?

I need to be able to access that data to edit it but I don’t know where it’s coming from…

Hi,

To fix this, you can try adding the code below in your child theme’s functions.php file

function x_integrity_comment( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    switch ( $comment->comment_type ) :
      case 'pingback' :  // 1
      case 'trackback' : // 1
    ?>
    <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
      <p><?php _e( 'Pingback:', '__x__' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', '__x__' ), '<span class="edit-link">', '</span>' ); ?></p>
    <?php
        break;
      default : // 2
      GLOBAL $post;
      if ( X_WOOCOMMERCE_IS_ACTIVE ) :
        $rating = esc_attr( get_comment_meta( $GLOBALS['comment']->comment_ID, 'rating', true ) );
      endif;
      $avatar_variation = ( x_is_product() ) ? ' x-img-thumbnail' : '';
    ?>
    <li id="li-comment-<?php comment_ID(); ?>" itemprop="review" itemscope itemtype="http://schema.org/Review" <?php comment_class(); ?>>
      <?php
      printf( '<div class="x-comment-img">%1$s %2$s</div>',
        '<span class="avatar-wrap cf' . $avatar_variation . '">' . get_avatar( $comment, 120 ) . '</span>',
        ( $comment->user_id === $post->post_author ) ? '<span class="bypostauthor">' . __( 'Post<br>Author', '__x__' ) . '</span>' : ''
      );
      ?>
      <article id="comment-<?php comment_ID(); ?>" class="comment">
        <header class="x-comment-header">
        
<div class="visually-hidden" itemprop="itemReviewed" itemscope itemtype="http://schema.org/Thing">
  <span itemprop="name"><?php the_title(); ?></span>
</div>
          <?php
          printf( '<cite class="x-comment-author" itemprop="author">%1$s</cite>',
            get_comment_author_link()
          );
          printf( '<div><a href="%1$s" class="x-comment-time"><time itemprop="datePublished" datetime="%2$s">%3$s</time></a></div>',
            esc_url( get_comment_link( $comment->comment_ID ) ),
            get_comment_time( 'c' ),
            sprintf( __( '%1$s at %2$s', '__x__' ),
              get_comment_date(),
              get_comment_time()
            )
          );
          edit_comment_link( __( '<i class="x-icon-edit" data-x-icon-s="&#xf044;"></i> Edit', '__x__' ) );
          ?>
          <?php if ( x_is_product() && get_option('woocommerce_enable_review_rating') == 'yes' ) : ?>
            <div class="star-rating-container">
              <div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating" class="star-rating" title="<?php echo sprintf( __( 'Rated %d out of 5', '__x__' ), $rating ) ?>">
                <span style="width:<?php echo ( intval( get_comment_meta( $GLOBALS['comment']->comment_ID, 'rating', true ) ) / 5 ) * 100; ?>%"><strong itemprop="ratingValue"><?php echo intval( get_comment_meta( $GLOBALS['comment']->comment_ID, 'rating', true ) ); ?></strong> <?php _e( 'out of 5', '__x__' ); ?></span>
              </div>
            </div>
          <?php endif; ?>
        </header>
        <?php if ( '0' == $comment->comment_approved ) : ?>
          <p class="x-comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', '__x__' ); ?></p>
        <?php endif; ?>
        <section class="x-comment-content" itemprop="description">
          <?php comment_text(); ?>
        </section>
        <?php if ( ! x_is_product() ) : ?>
        <div class="x-reply">
          <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span class="comment-reply-link-after"><i class="x-icon-reply" data-x-icon-s="&#xf3e5;"></i></span>', '__x__' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
        </div>
        <?php endif; ?>
      </article>
    <?php
        break;
    endswitch;
  }

Hope this helps

1 Like

Hi, thank you.

Is there instructions on how to do this?

I’m don’t have a lot of developer resources available so it’s something I will need to implement myself.

I’m also curious as to how this issue hasn’t come up before if the theme doesn’t already include the code you just gave me?

Shouldn’t the theme automatically have this accounted for?

Thanks again for getting back to me.

Hello There,

Please go to Appearance > Editor and find the child theme’s functions.php file. Once you have loaded it, you can add the code given by Paul in his reply.

And if Appearance > Editor is not present, then you will need to log in to your FTP, browse to the theme’s folder and edit the file in there. This method is a bit complicated for newbie users.

To better assists you with this issue, would you mind providing us the url of your site with login credentials so we can take a closer look? To do this, you can make a post with the following info:
– Link to your site
– WordPress Admin username / password

  • FTP Hostname
  • FTP Username
  • FTP Password

To know how to create a secure note, please check this out: https://theme.co/apex/forum/t/how-to-get-support/288

Thank you.

Thanks for your help,

I have provided a secure note with all the requested info.

Cheers.

Hi There,

Upon checking your website, I could see that you didn’t setup a child theme yet. I recommend you to install and activate the child theme first:

After that navigate to the file editor: https://thomasinaction.com/wp-admin/theme-editor.php

Then edit the functions.php file locates in the child theme, just need to paste the provided code at the end of this file.

Let us know how it goes!

Hey there, thanks for this.

I’ve worked it out but this is what is now happening: https://www.useloom.com/share/62adbfa297bc4a4e9c05124b5734e047

It’s saying there is 4 errors that need to be fixed before implementation can occur.

Actually scratch that. I updated it successfully but the errors have not cleared…

see here: https://www.useloom.com/share/26b6e92a7faf4d61839eaab261b6354b

Hey @upskillacademy,

I noticed you placed the code in styles.css. Please put the PHP code in functions.php.

Thanks.

Heya,

Thanks for that.

It worked on one post but not the other. See here: https://www.useloom.com/share/5c0b78b554e249919f0863ccdea54e0b

Hi There,

I notice that the site is under CloudFlare, please clear all your caching features (plugin, server-side, CDN), this will help the site apply the changes immediately.

Clear caching plugins
CloudFlare - How do I purge my cache

We’ve also added this to our issue tracker, so the developers will be made aware of it.

Thanks,

YAY! all fixed. So happy with that. Thank you.

You’re more than welcome, glad we could help.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.