添加“if”条件时脚本不起作用

问题描述 投票:0回答:1
我正在尝试直接添加一段架构,因为我无法通过 Yoast SEO 使其工作。

如果我只使用我创建的 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>'; }
    
wordpress schema
1个回答
0
投票
如果您启用了 Yoast SEO,则应使用过滤器

wpseo_schema_graph

wpseo_schema_graph_pieces
,如
此处所述。

© www.soinside.com 2019 - 2024. All rights reserved.