首页 > 解决方案 > 如何将结构化数据标记中的 markup.html 放置在 Wordpress 页面中

问题描述

我的 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>

标签: htmlwordpressstructured-data

解决方案


看看这里: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');

推荐阅读