Skip to content
Custom fields for WordPress that are quick to build and quick to load. Get Pro

Content on the page

An FAQ, with structured data

Questions and answers on the page, and the same ones as structured data for search engines.

1 minute Works with the free plugin

The FAQ on the site, with one answer open
The FAQ on the site, with one answer open.

Fields. faq (Repeater): question (Text), answer (Rich text).

PHP
<?php $items = ugly_rows( 'faq' ); ?>

<?php foreach ( $items as $item ) : ?>
	<details>
		<summary><?php $item->show( 'question' ); ?></summary>
		<?php $item->show( 'answer' ); ?>
	</details>
<?php endforeach; ?>

<?php
if ( $items ) {
	$schema = array(
		'@context'   => 'https://schema.org',
		'@type'      => 'FAQPage',
		'mainEntity' => array_map(
			static fn ( $item ) => array(
				'@type'          => 'Question',
				'name'           => wp_strip_all_tags( $item->get( 'question' ) ),
				'acceptedAnswer' => array(
					'@type' => 'Answer',
					'text'  => wp_kses_post( $item->get( 'answer' ) ),
				),
			),
			$items
		),
	);

	echo '<script type="application/ld+json">' . wp_json_encode( $schema ) . '</script>';
}