html - 如何将结构化数据标记中的 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>
解决方案
看看这里: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');
推荐阅读
- typo3 - 手动将 Typo3 版本 7 升级到 Typo3 版本 9 后图像不显示
- azure - 配置 Azure 负载均衡器的入站安全规则
- azure - 从 Azure 按时间戳顺序读取文件
- java - Fragment 没有从 ViewModel 中获得价值
- reactjs - 如何将 this.setState 转换为 setItemIdToSelectedMap?
- python - PyTorch - 将 ProGAN 代理从 pth 转换为 onnx
- node.js - 连接到 Oracle 数据库并在 Web 浏览器中显示内容
- powerbuilder - PowerBuilder 数据存储限制
- javascript - node-ffi-napi 在方法调用上没有收到来自 dll 的任何响应,可能是结构问题?
- windows - 有没有办法在 Windows PowerShell 中获得 Git 体验?