Skip to content

Instantly share code, notes, and snippets.

@justintadlock
Last active November 13, 2025 19:56
Show Gist options
  • Select an option

  • Save justintadlock/7771e776397cdbd41c169a2758836353 to your computer and use it in GitHub Desktop.

Select an option

Save justintadlock/7771e776397cdbd41c169a2758836353 to your computer and use it in GitHub Desktop.
WordPress Accordion Block w/FAQ Schema
<?php
// You need to add an `is-faqs` class to the wrapping Accordion block to trigger the
// below markup changes.
add_filter('render_block_core/accordion', function ($content) {
$processor = new \WP_HTML_Tag_Processor($content);
if (! $processor->next_tag([ 'class_name' => 'is-faqs' ])) {
return $processor->get_updated_html();
}
$processor->set_attribute('itemscope', true);
$processor->set_attribute('itemtype', 'https://schema.org/FAQPage');
while ($processor->next_tag([ 'class_name' => 'wp-block-accordion-item' ])) {
$processor->set_attribute('itemscope', true);
$processor->set_attribute('itemprop', 'mainEntity');
$processor->set_attribute('itemtype', 'https://schema.org/Question');
if ($processor->next_tag(['class_name' => 'wp-block-accordion-heading__toggle-title'])) {
$processor->set_attribute('itemprop', 'name');
}
if ($processor->next_tag([ 'class_name' => 'wp-block-accordion-panel' ])) {
$processor->set_attribute('itemscope', true);
$processor->set_attribute('itemprop', 'acceptedAnswer');
$processor->set_attribute('itemtype', 'https://schema.org/Answer');
if ($processor->next_tag('p')) {
$processor->set_attribute('itemprop', 'text');
}
}
}
return $processor->get_updated_html();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment