Hubert just completed a project for Pipedrive, so downloaded those templates. I kept the old ones as the Pipedrive team noticed some things were overwritten. So until they are fully in production and working correctly, I'm keeping two copies. Will update with the correct files once Hubert investigates.
This commit is contained in:
@ -0,0 +1,30 @@
|
||||
{% comment %} This is generic code that will make ld+json tag from any FAQ on page {% endcomment %}
|
||||
<script>
|
||||
addEventListener('DOMContentLoaded', () => {
|
||||
let ldTag = `
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "FAQPage",
|
||||
"mainEntity": [`;
|
||||
document.querySelectorAll('.faq-element').forEach(faq_element => {
|
||||
let question = faq_element.querySelector('.faq-question-text').querySelector('.lang-en').innerHTML.replaceAll('"', '\"');
|
||||
let answer = faq_element.querySelector('.faq-answer').querySelector('.lang-en').innerHTML.replaceAll('"', '\"');
|
||||
let faq_part = `
|
||||
{
|
||||
"@type": "Question",
|
||||
"name": "${question.replaceAll('"', '\\"')}",
|
||||
"acceptedAnswer": {
|
||||
"@type": "Answer",
|
||||
"text": "${answer.replaceAll('"', '\\"')}"
|
||||
}
|
||||
},`;
|
||||
ldTag = ldTag.concat(faq_part);
|
||||
})
|
||||
ldTag = ldTag.slice(0, -1) + `
|
||||
]
|
||||
}
|
||||
<\/script>`
|
||||
document.head.insertAdjacentHTML('beforeend', ldTag)
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user