Skip to content

Instantly share code, notes, and snippets.

@daviddarke
Created October 4, 2016 08:25
Show Gist options
  • Select an option

  • Save daviddarke/61012c2c2b07ee5f358ccff53a036b19 to your computer and use it in GitHub Desktop.

Select an option

Save daviddarke/61012c2c2b07ee5f358ccff53a036b19 to your computer and use it in GitHub Desktop.
Wordpress version of Google's structured data
<?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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment