Skip to content

Instantly share code, notes, and snippets.

@pacotole
Created June 1, 2021 11:53
Show Gist options
  • Save pacotole/6b805aac994c4723fa6e466b0044d02c to your computer and use it in GitHub Desktop.
Save pacotole/6b805aac994c4723fa6e466b0044d02c to your computer and use it in GitHub Desktop.
Shortcode to output Review Structured Data ld+json
<?php
/**
* Shortcode to output Review Structured Data ld+json
*
* Example: to use in Tesminonial CPT
* Usage: [review_json]
*/
function review_structured_data_shortcode() {
$post_id = get_the_ID();
$ldjson = [
"@context" => "https://schema.org/",
"@type" => "Review",
"itemReviewed" => [
"@type" => "ProfessionalService",
"@id" => get_home_url(),
"name" => get_bloginfo('name'),
"image" => the_seo_framework()->get_option('social_image_fb_url'),
"address" => [
"@type" => "PostalAddress",
"addressLocality" => "Madrid",
"addressCountry" => "ES",
],
],
"reviewRating" => [
"@type" => "Rating",
"ratingValue" => "5",
],
"author" => [
"@type" => "Person",
"name" => get_the_title( $post_id ),
"jobTitle" => get_post_meta( $post_id, 'job'),
],
"reviewBody" => get_post_meta( $post_id, 'comment'),
];
return '<script type="application/ld+json">' . wp_json_encode( $ldjson ) . '</script>';
}
add_shortcode( 'review_json', 'review_structured_data_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment