如何在Wordpress页面中将结构化数据标记中的markup.html放置

问题描述 投票:0回答:1

我的Google分析帐户建议我在Head部分的网页中添加结构化数据标记。我标记了我想要的内容并创建了HTML。但是,当我将该代码放在我标记的页面上的HTML中时,我没有看到Head部分。所以,我只是把它放在页面的顶部。当我将它添加到页面顶部时,它会创建一个空格。可以将此代码放在页面底部。代码如下所示:

 <!-- JSON-LD markup generated by Google Structured Data Markup Helper. -->
 <script type="application/ld+json">
 [ {
 "@context" : "http://schema.org",
 "@type" : "Product",
  "description" : "IT Training Courses",
  "url" : "https://mindiq.com/it-training-course-list-application- 
   development- 
    java/"
    }, {
   "@context" : "http://schema.org",
   "@type" : "Product",
  "description" : "IT Training Courses",
  "url" : "https://mindiq.com/pythonl-training-onsite-tailored-low-cost/"
   } ]
  </script>
html wordpress structured-data
1个回答
0
投票

看看这里:https://codex.wordpress.org/Plugin_API/Action_Reference/wp_head

<?php
add_action('wp_head', 'your_function');
?>

functions.php中,用你的结构数据HTML创建your_function(),该函数应该在<head>中加载它

function your_function() {
?>
 <!-- JSON-LD markup generated by Google Structured Data Markup Helper. -->
 <script type="application/ld+json">
 [ {
 "@context" : "http://schema.org",
 "@type" : "Product",
  "description" : "IT Training Courses",
  "url" : "https://mindiq.com/it-training-course-list-application- 
   development- 
    java/"
    }, {
   "@context" : "http://schema.org",
   "@type" : "Product",
  "description" : "IT Training Courses",
  "url" : "https://mindiq.com/pythonl-training-onsite-tailored-low-cost/"
   } ]
  </script>
<?php
}

add_action('wp_head', 'your_function');
© www.soinside.com 2019 - 2024. All rights reserved.