PHP Generate AMP required Schema.org LD+JSON

Auto-generate basic schema.org structured data required for Google's new AMP specification.
<script type="application/ld+json">
  {
    "@context": "http:\/\/schema.org",
    "@type": "NewsArticle",
    "headline": "<?php echo 'My Site Name ' . ucwords(preg_replace('/\.php$/', '', basename($_SERVER['PHP_SELF']))); ?>",
    "dateModified": "<?php echo str_replace('+00:00', 'Z', date('c', filemtime (basename($_SERVER['SCRIPT_NAME'])))); ?>",
    "mainEntityOfPage": <?php echo json_encode('http://' .  $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']); ?>,
    "image":{"@type":"ImageObject","url": <?php echo json_encode('MY_BANNER_URL'); ?>,"width": 1024,"height":512},
    "datePublished":"2016-03-03T11:12:16Z",
    "author":{"@type":"Person","name":"AUTHOR OF PAGE"},
    "publisher":{"@type":"Organization","name":"COMPANY_NAME","logo":{"@type":"ImageObject","url": <?php echo json_encode('COMPANY_LOGO_URL'); ?>,"width":512,"height":256}}
  }
</script>
Posted by
Snippet Viewed 1670 times.

Share your PHP code snippets:

  • Get some recognition & link back to your site.

 

Submit | Browse

Most Recent php snippets

Most Viewed