Titel, leicht gekürzt
$fallback = get_the_excerpt( $post_id );
if ( empty( $fallback ) ) {
$fallback = get_the_title( $post_id );
}
$description = wp_trim_words( wp_strip_all_tags( $fallback ), 30, '…' );
}
$name = get_the_title() ?: "Studenten Tipps";
$image = get_the_post_thumbnail_url(get_the_ID(), 'full') ?: "https://www.nachhilfe-team.net/fb_full_size_thumbnail.png";
$priceValidUntil = "2050-12-31T23:59";
$ratingValue = 4.90;
$ratingCount = 2721;
$priceCurrency = "EUR";
$price = 0;
$structuredData = [
"@context" => "https://schema.org/",
"@id" => $id,
"@type" => "Product",
"brand" => [
"@type" => "Brand",
"name" => "Nachhilfe-Team.net"
],
"sku" => "ntn-sku-" . get_the_ID(),
"mpn" => "ntn-mpn-" . get_the_ID(),
"description" => $description,
"name" => $name,
"image" => $image,
"offers" => [
"@type" => "Offer",
"availability" => "https://schema.org/InStock",
"price" => floatval($price),
"priceValidUntil" => $priceValidUntil,
"priceCurrency" => $priceCurrency,
"url" => $id
],
"review" => [
"@type" => "Review",
"reviewRating" => [
"@type" => "Rating",
"ratingValue" => 4.9,
"bestRating" => 5
],
"author" => [
"@type" => "Person",
"name" => "Frank Olschewski"
]
],
"aggregateRating" => [
"@type" => "AggregateRating",
"ratingValue" => floatval($ratingValue),
"bestRating" => 5,
"ratingCount" => intval($ratingCount)
]
];
// Hier kommt die saubere Ausgabe im Heredoc-Format:
$json = json_encode($structuredData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
echo <<
$json
EOT;
?>