Last active
February 28, 2020 04:53
-
-
Save benjaminadk/ff1462dd98f7dc3d585cbe6bf3b24b78 to your computer and use it in GitHub Desktop.
BlogPosting Schema PHP
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 | |
function is_blog() { | |
return (is_archive() || is_author() || is_category() || is_home() || is_single() || is_tag() && 'post' == get_post_type()); | |
} | |
?> | |
<?php if (is_blog()) : | |
$tags = get_tags(); | |
$keywords = ''; | |
foreach ($tags as $tag) { | |
$keywords .= $tag->name . ' '; | |
} | |
?> | |
<script type="application/ld+json"> | |
{ | |
"@context": "https://schema.org", | |
"@type": "BlogPosting", | |
"headline": "<?php echo get_post_field('post_title'); ?>", | |
"image": "<?php echo get_the_post_thumbnail_url(); ?>", | |
"keywords": "<?php echo trim($keywords); ?>", | |
"url": "<?php echo get_permalink(); ?>", | |
"dateCreated": "<?php echo substr(get_post_field('post_date'), 0, 10); ?>", | |
"datePublished": "<?php echo substr(get_post_field('post_date'), 0, 10); ?>", | |
"dateModified": "<?php echo substr(get_post_field('post_modified'), 0, 10); ?>", | |
"description": "<?php echo get_post_field('post_excerpt'); ?>", | |
"mainEntityOfPage ": { | |
"@type": "WebPage", | |
"@id": "<?php echo get_permalink(); ?>" | |
}, | |
"publisher": { | |
"@type": "Organization", | |
"name": "LA Design Concepts", | |
"logo": { | |
"@type": "ImageObject", | |
"url": "https://ladesignconcepts.com/images/ladc_logo0820.png", | |
"width": 50, | |
"height": 50 | |
} | |
}, | |
"author": { | |
"@type": "Person", | |
"name": "Tyler Shepherd" | |
} | |
} | |
</script> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment