Skip to content

Instantly share code, notes, and snippets.

@benjaminadk

benjaminadk/blogpost.php

Last active Feb 28, 2020
Embed
What would you like to do?
BlogPosting Schema PHP
<?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