Skip to content

Instantly share code, notes, and snippets.

@KartikWatts
Last active May 5, 2023 13:01
Show Gist options
  • Save KartikWatts/14c652dc64c15a812dd0486473defa1b to your computer and use it in GitHub Desktop.
Save KartikWatts/14c652dc64c15a812dd0486473defa1b to your computer and use it in GitHub Desktop.
Custom Html Script for `BlogPosting` type `Article` in Google structured data
<script>
(function(){
var schema=
{
"@context": "http://schema.org",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{Page URL}}
},
"headline": {{Blog_Headline}},
"image": {
"@type": "ImageObject",
"url": {{Blog_Image_URL}},
},
"author": {
"@type": "Person",
"name": {{Blog_Author_Name}},
"url": {{Blog_Author_URL}}
},
"datePublished": {{Blog_Date_Published}},
"publisher": {
"@type": "Organization",
"name": {{Blog_Publisher_Name}},
"logo": {
"@type": "ImageObject",
"url": {{Blog_Publisher_Logo_URL}},
}
},
"description": {{Blog_Description}}
}
// TODO:: These details can be added
// "dateModified": {{Blog_Date_Modified}},
var script=document.createElement('script');
script.type="application/ld+json";
script.innerHTML=JSON.stringify(schema);
document.getElementsByTagName('head')[0].appendChild(script);
})(document);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment