Problem/Motivation

When I use an FAQ block in layout builder I would like it to automatically add structured data to the page.

Proposed resolution

In the rocketship_blocks.module we can attach the json ld information to the head of the site for each block it finds on the page.

Similarly to how easy breadcrumb module does it: https://git.drupalcode.org/issue/easy_breadcrumb-3292422/-/blob/3292422-...

The structure of the json would be as follows:

This is an example FAQ title
This is the resulting FAQ answer. Which will also be added in the structured data of this page so Google can process it accordingly.

This is a second FAQ item
This is the answer to the second item.

Structured data to be added in the source code for above example:

<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [{
"@type": "Question",
"name": "This is an example FAQ title",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the resulting FAQ answer. Which will also be added in the structured data of this page so Google can process it accordingly."
}
},{
"@type": "Question",
"name": "This is a second FAQ item",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the answer to the second item."
}
}]
}
</script>

For each FAQ block on the page it should have another script tag of structured data.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nielsaers created an issue. See original summary.

HitchShock’s picture

Status: Active » Needs review
FileSize
5.49 KB

Implemented SOE solution for FAQ block.

sdstyles’s picture

Status: Needs review » Reviewed & tested by the community

The patch works as expected, the FAQ data is injected into the page.

nginex’s picture

FileSize
5.55 KB
3.48 KB

Code cleaning and refactoring.

  • cf7ddbd committed on 6.x
    Issue #3292460 by nginex, HitchShock, nielsaers, sdstyles: I would like...
nginex’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.