2020-02-08, 05:24 PM
(This post was last modified: 2020-02-08, 06:19 PM by artwork79. Edited 3 times in total.)
I've added Google Structured Data to my forums thread pages successfully using the following code in the <head> code of the showthread template
However, I need to add the dateModified property as well, and have got it to work for the datePublished using:
But I can't work out how to modify the above datePublished code for dateModified
Can anyone help?
I've solved it. dateModified needs to be changed to the following:
So the full code to use for Google Structured Data in the showthread template is:
The next issue, is that the dateModified now shows correctly for older posts, but for new posts it shows the word Today, which is not valid for Google Structured Data.
So can someone help me to change it so it only shows the date always?
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage"
},
"headline": "{$thread['subject']} - Page {$page}",
"datePublished": "<?=my_date($mybb->settings['dateformat'], $thread['dateline'])?>",
"dateModified": "",
"image": {
"@type": "ImageObject",
"height": "REPLACE_ME",
"width": "REPLACE_ME",
"url": "REPLACE_ME"
},
"author": "{$thread['username']}",
"publisher": {
"@type": "Organization",
"logo": {
"@type": "ImageObject",
"url": "REPLACE_ME"
},
"name":"REPLACE_ME",
"sameAs":[
"https://twitter.com/REPLACE_ME",
"https://www.youtube.com/channel/REPLACE_ME"
],
"url":"REPLACE_ME"
},
"articleBody": ""
}
</script>
However, I need to add the dateModified property as well, and have got it to work for the datePublished using:
"datePublished": "<?=my_date($mybb->settings['dateformat'], $thread['dateline'])?>",
But I can't work out how to modify the above datePublished code for dateModified
Can anyone help?
I've solved it. dateModified needs to be changed to the following:
"dateModified": "<?=my_date($mybb->settings['dateformat'], $thread['lastpost'])?>",
So the full code to use for Google Structured Data in the showthread template is:
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage"
},
"headline": "{$thread['subject']} - Page {$page}",
"datePublished": "<?=my_date($mybb->settings['dateformat'], $thread['dateline'])?>",
"dateModified": "<?=my_date($mybb->settings['dateformat'], $thread['lastpost'])?>",
"image": {
"@type": "ImageObject",
"height": "REPLACE_ME",
"width": "REPLACE_ME",
"url": "REPLACE_ME"
},
"author": "{$thread['username']}",
"publisher": {
"@type": "Organization",
"logo": {
"@type": "ImageObject",
"url": "REPLACE_ME"
},
"name":"REPLACE_ME",
"sameAs":[
"https://twitter.com/REPLACE_ME",
"https://www.youtube.com/channel/REPLACE_ME"
],
"url":"REPLACE_ME"
},
"articleBody": ""
}
</script>
The next issue, is that the dateModified now shows correctly for older posts, but for new posts it shows the word Today, which is not valid for Google Structured Data.
So can someone help me to change it so it only shows the date always?