: SEO and dynamic structured data (microdata) I'm wanting to have a very limited amount of structured data (ideally microdata) added using javascript, especially using the document's lastModified
I'm wanting to have a very limited amount of structured data (ideally microdata) added using javascript, especially using the document's lastModified property. It seems rather bizarre and counter-intuative to have to update the structured data for each small edit on a webpage.
According to this and google's documentation the best way to do this is to use JSON-LD rather than microdata. I've looked at the JSON-LD documentation and examples but as far as I am unable to find an example of this. How do I do this?
The page currently has the javascript that sets the contents (innerHTML) of <span id="moddate"></span> to the lastModified date.
This is the JSON-LD I have so far, how do I made modifiedDate work via javascript?
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebPage",
"author": "http://plus.google.com/12345678",
"breadcrumb": "Articles > MedicalArticle > Psychology",
"datePublished": "2014-05-01",
"dateModified": "2015-05-01",
}
</script>
The is already existing microdata for the WebPage schema including author and additional fields.
More posts by @Marchetta884
1 Comments
Sorted by latest first Latest Oldest Best
this involved a code snippet and needs jquery plus moment.js to set the citation_online_data meta tag to the current date.
Add to the <head> tag
<script type="text/javascript">
$(document).ready(function(){
var dateModified = moment(document.lastModified).format("YYYY/MM/DD");
$('head').append( '<meta name="citation_online_date" content="' + dateModified + '">');
//create JSON-LD for lastModified and citation_online_date
var el = document.createElement('script');
el.type = 'application/ld+json';
el.id = 'jsonld';
el.text = JSON.stringify({ "@context": "http://schema.org", "@type": "WebPage", "url": "http:"+window.location.href, "datePublished": "+dateModified+" });
$('body').append(el);
});
</script>
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.