php Wordpress版Google的结构化数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Wordpress版Google的结构化数据相关的知识,希望对你有一定的参考价值。

<?php
$post_thumbnail_id = get_post_thumbnail_id($post->ID);
$post_thumbnail_url = wp_get_attachment_image_src( $post_thumbnail_id );
?>
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Article",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "<?php the_permalink(); ?>"
  },
  "headline": "<?php the_title(); ?>",
  "image": {
    "@type": "ImageObject",
    "url": "<?php echo $post_thumbnail_url[0]; ?>",
    "height":<?php echo $post_thumbnail_url[1]; ?>,
    "width": <?php echo $post_thumbnail_url[2]; ?>
  },
  "datePublished": "<?php echo get_the_date('c') ?>",
  "dateModified": "<?php the_modified_date('c') ?>",
  "author": {
    "@type": "Person",
    "name": "<?php echo get_the_author() ?>"
  },
   "publisher": {
    "@type": "Organization",
    "name": "NAME_OF_SITE",
    "logo": {
      "@type": "ImageObject",
      "url": "SITE_LOGO",
      "width": 600,
      "height": 60
    }
  },
  "description": "<?php the_excerpt(); ?>"
}
</script>

以上是关于php Wordpress版Google的结构化数据的主要内容,如果未能解决你的问题,请参考以下文章

PHP 针对WordPress优化的Google Analytics

PHP Google翻译为WordPress

php 将Google字体添加到Wordpress(正确的方式)

scss Wordpress - 将Google字体添加到functions.php

php 将Google Analytics跟踪代码添加到WordPress的简单插件

php 用于下载/邮件/出站链接的Wordpress Google Analytics跟踪代码。