Last active
August 8, 2019 02:36
-
-
Save wadadanet/2d410016a8a1394be4fcce9317711b66 to your computer and use it in GitHub Desktop.
wordpress JSON-LD example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$type = "WebPage"; // BlogPosting, WebSite, Article, Person, SearchAction, NewsArticle | |
$author_name = get_the_author_meta('display_name'); | |
$logo_url = "https://www.coffee-break-designs.com/wp-content/themes/coffee-break-designs-v8/img/logo.svg"; | |
$description = get_post_meta(get_the_id(), "_aioseop_description", true); | |
$thumbnail_id = get_post_thumbnail_id(); | |
$imageobject = wp_get_attachment_image_src( $thumbnail_id, 'full' ); | |
?> | |
<script type="application/ld+json"> | |
{ | |
"@context": "http://schema.org", | |
"@type": "<?= $type ?>", | |
"mainEntityOfPage":{ | |
"@type":"WebPage", | |
"@id":"<?php the_permalink() ?>" | |
}, | |
"headline":"<?php the_title() ?>", | |
"image": { | |
"@type": "ImageObject", | |
"url": "<?= $imageobject[0] ?>", | |
"height": "<?= $imageobject[2] ?>", | |
"width": "<?= $imageobject[1] ?>" | |
}, | |
"datePublished": "<?= esc_attr( get_the_date( 'c' )) ?>", | |
"dateModified": "<?= esc_attr( get_the_modified_date( 'c' )) ?>", | |
"author": { | |
"@type": "Person", | |
"name": "<?= $author_name ?>" | |
}, | |
"publisher": { | |
"@type": "Organization", | |
"name": "<?php bloginfo('name'); ?>", | |
"logo": { | |
"@type": "ImageObject", | |
"url": "<?= $logo_url ?>", | |
"width": 300, | |
"height": 69 | |
} | |
}, | |
"description": "<?= $description ?>" | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment