forked from xserver-inc/cocoon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
json-ld-review.php
47 lines (45 loc) · 1.3 KB
/
json-ld-review.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
//JSON-LDに関する記述
//https://developers.google.com/search/docs/data-types/articles
//https://schema.org/NewsArticle
//https://fantastech.net/review-snippet-customize
/**
* Cocoon WordPress Theme
* @author: yhira
* @link: https://wp-cocoon.com/
* @license: http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
*/
if ( !defined( 'ABSPATH' ) ) exit;
$author = (get_the_author_meta('display_name') ? get_the_author_meta('display_name') : get_bloginfo('name'));
$review_type = get_the_review_type() ? get_the_review_type() : 'Product';
?>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Review",
"itemReviewed": {
"@type": "<?php echo esc_attr($review_type); ?>",
"name": "<?php echo esc_attr(get_the_review_name()); ?>",
"review":{
"author": {
"@type": "Person"
}
}
},
"reviewRating": {
"@type": "Rating",
"ratingValue": "<?php echo esc_attr(sprintf('%.1f', get_the_review_rate())); ?>",
"bestRating": "5",
"worstRating": "0"
},
"datePublished": "<?php echo esc_attr(get_seo_post_time()); ?>",
"author": {
"@type": "Person",
"name": "<?php echo esc_attr($author); ?>"
},
"publisher": {
"@type": "Organization",
"name": "<?php echo esc_attr(get_bloginfo( 'name' )); ?>"
}
}
</script>