Schema.org FAQ utility

Connect your template data to generate FAQ schema on a page

Basic usage example

faq_items in this example is hard-coded. But you would replace with your own data fields.

{% set faq_items = [
    {
        'answer_text': 'Answer to question 1',
        'question_name': 'Question 1?'
    },
    {
        'answer_text': 'Answer to question 2',
        'question_name': 'Question 2?'
    }
] %}

<script type="application/ld+json">
{{ faq_items|as_faq_schema|tojson|safe }}
</script>

Using custom field data example

Looping over some custom field values to generate the FAQ items.

{% set faq_items = [] %}
{% for i in range(1, 5) %}
  {% set title_value_key = 'faq_title_text_%s' % i %}
  {% set description_value_key = 'faq_description_text_%s' % i %}
  {% if site.custom_fields[title_value_key] %}
    {% do faq_items.append({
        'question_name': site.custom_fields[title_value_key],
        'answer_text': site.custom_fields[description_value_key]
    }) %}
  {% endif %}
{% endfor %}

<script type="application/ld+json">
{{ faq_items|as_faq_schema|tojson|safe }}
</script>

Last updated