How to add FAQPage Schema Markup for Google
Although the theme includes an option to enable inline Question/Answer schema for the Toggle element, Google Search Console may not consistently recognize this markup and may report related errors.
Since your questions and answers are being added through a page builder, it would be inefficient for the theme to continuously scan page content for FAQs and automatically generate schema markup. Doing so could lead to markup conflicts and may negatively impact site performance.
If you want to provide reliable, Google-compliant schema markup for your FAQ page, the recommended approach is to use a custom code snippet.
The snippet below scans the page, identifies all Toggle elements, generates valid FAQPage schema markup, and injects it into the page.
Important: Be sure to replace both occurrences of YOUR_FAQ_PAGE_ID_OR_SLUG in the code snippet so that it properly targets your specific FAQ page.
Additionally, this code is written specifically to work with the theme's "Toggle" element - if you are using a different method for inserting FAQ's on the page, the code will need to be modified accordingly.
/**
* Insert custom FAQPage schema markup for the FAQ page.
*/
add_action( 'wp_head', function () {
$page = 'YOUR_FAQ_PAGE_ID_OR_SLUG';
if ( ! is_page( $page ) ) {
return;
}
global $post;
if ( empty( $post->post_content ) ) {
return;
}
$pattern = get_shortcode_regex( [ 'vcex_toggle' ] );
$content = $post->post_content;
if ( ! preg_match_all( '/'.$pattern.'/s', $content, $matches, PREG_SET_ORDER ) ) {
return;
}
$faq_items = [];
foreach ( $matches as $shortcode ) {
$atts = shortcode_parse_atts( $shortcode[3] );
if ( empty( $atts['heading'] ) || empty( $shortcode[5] ) ) {
continue;
}
$question = wp_strip_all_tags( $atts['heading'] );
// Process nested shortcodes inside answer
$answer = do_shortcode( $shortcode[5] );
$answer = wp_strip_all_tags( $answer );
$faq_items[] = [
"@type" => "Question",
"name" => $question,
"acceptedAnswer" => [
"@type" => "Answer",
"text" => $answer
]
];
}
if ( empty( $faq_items ) ) {
return;
}
$schema = [
"@context" => "https://schema.org",
"@type" => "FAQPage",
"mainEntity" => $faq_items
];
echo "\n<script type=\"application/ld+json\">\n";
echo wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES );
echo "\n</script>\n";
}, 99 );
/**
* Disable the Yoast Schema markup on the FAQ page.
*/
add_filter( 'wpseo_json_ld_output', function( $data ) {
$page = 'YOUR_FAQ_PAGE_ID_OR_SLUG';
if ( is_page( $page ) ) {
return false;
}
return $data;
}, 10, 1 );We recommend Code Snippets (100% Free) or WPCode (sponsored)