如果我只使用我创建的 JSON 数组,则会添加代码,但是当我通过页面 ID 添加条件时,它不起作用,我错过了什么?
该页面是自定义帖子类型单页。
global $post;
if( $post->ID == 1385 ){
$arrJson = array(
'@context' => 'https://schema.org/',
'@type' => 'AggregateRating',
"ratingValue" => "4.93",
"bestRating" => "5",
"ratingCount" => "18",
"itemReviewed" => array(
'@type' => 'Hospital',
'name' => 'Practice Plus Group Hospital Barlborough',
'telephone' => '0330 053 6443',
"address" => array (
"@type" => "PostalAddress",
"streetAddress" => "2 Lindrick Way",
"addressLocality" => "Barlborough",
"addressRegion" => "Chesterfield",
"postalCode" => "S43 4XE",
"addressCountry" => "UK"
),
),
);
echo '<script type="application/ld+json">';
echo json_encode($arrJson);
echo '</script>';
}