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

时间:2018-08-30 15:13:34

标签: html wordpress structured-data

我的Google Analytics(分析)帐户建议我在“标题”部分的网页中添加结构化数据标记。我标记了想要的内容并创建了HTML。但是,当我将该代码放到我标记的页面的HTML中时,我看到“标题”部分。因此,我只是将其放在页面顶部。当我将其添加到页面顶部时,它将创建一个空间。可以将这段代码放在页面底部。代码如下:

 <!-- 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>

1 个答案:

答案 0 :(得分: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');