CreareSEO
CreareSEO copied to clipboard
Rich Snippet with Yotpo Review system
Hello, I use your plugin and works great. I want to know how can I use Rich Snippet with Yotpo. https://goo.gl/hBP7P3 Is that possible? Regards,
As far as I can see both extensions should be compatible. Have you noticed any conflicts?
I had some problems with creare & yotpo, and ran across this to-do as I was trying to figure out what to do.
Looks like the Creare SEO doesn't see the yotpo reviews at all... So, you need to pull in the rich snippet from yotpo and insert them.
Find this file /app/design/frontend/<theme-package>/<theme-template>/template/creareseo/product/schema.phtml
Delete line 30 to the end of the file.
}<?php if ($this->getReviewsCount()) : ?>,
"review": [
<?php foreach ($this->_productReviews as $review) : ?>
{
"@type": "Review",
"author": "<?php echo $review->getNickname() ?>",
"datePublished": "<?php echo date('Y-d-m', strtotime($review->getCreatedAt())) ?>",
"description": "<?php echo $this->cleanString($review->getDetail()) ?>",
"name": "<?php echo $review->getTitle() ?>"<?php $_averageRating = $this->getAverageRating($review->getReviewId()) ?><?php if ($_averageRating >= 1) : ?>,
"reviewRating": {
"@type": "Rating",
"bestRating": "5",
"ratingValue": "<?php echo $_averageRating ?>",<?php $_totalAverageRating += $_averageRating ?>
"worstRating": "1"
}
<?php endif ?>
}<?php echo ($_i != $this->getReviewsCount() ? ',' : '') ?>
<?php $_i++ ?>
<?php endforeach ?>
],
"aggregateRating": {
"@type": "AggregateRating",
<?php $ratingValue = round($_totalAverageRating/$this->getReviewsCount(), 1) ?>
<?php if ($ratingValue > 0) : ?>
"ratingValue": "<?php echo $ratingValue ?>",
<?php else: ?>
"ratingValue": "1",
<?php endif ?>
"reviewCount": "<?php echo $this->getReviewsCount() ?>"
}
<?php endif ?>
}
</script>
and replace them with the following:
}<?php $array = $this->helper('yotpo/richSnippets')->getRichSnippet($this); ?>
<?php if ($array["reviews_count"] > 0): ?>,
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "<?php echo $array["average_score"]; ?>",
"reviewCount": "<?php echo $array["reviews_count"]; ?>"
}
<?php endif; ?>
}
</script>
This way only inserts the aggregate rating section if there's reviews in yotpo. Otherwise, it drops it.
Yotpo won't export all the individual reviews to go into the ld+json, so we need to drop the review
block. All you want in your final version of this file is the aggregate rating info.
Yep, I can second that. Optimally, you would check if the Yotpo extension is installed and active and if so, use the code provided by @sam327.
This is worth noting - you can only use rich snippets if you're on Yotpo's Pro plan or higher - it won't work on the starter plan.
The check to see if a module is installed and active is something like this: Mage::getConfig()->getModuleConfig('modulename')->is('active', 'true')
which you can use to write an if-check and wrap my code in...
However, if you're going in to edit this file to add the yotpo code, you really should know whether or not yotpo is installed. But my code seems to fail gracefully. I broke yotpo during development and nothing was majorly broken, I just got blank spaces. YMMV, of course.