Hi @mesmer7
Thanks for your patience. I just saw your messages, as our Support team doesn’t work over the weekend. I’d be happy to help you.
What you’re seeing is actually expected behavior. Most FAQ schema implementations (including Kadence) sanitize HTML inside the “Answer” field, and often strip attributes like href from <a> tags. This is done to keep the structured data compliant with Google’s guidelines and avoid invalid or potentially unsafe markup.
Try adding this custom code using the code snippets plugin: https://www.kadencewp.com/help-center/docs/kadence-theme/how-to-add-a-custom-filter-or-function-with-code-snippets/
add_filter( 'kadence_blocks_faq_schema_allowed_tags', 'custom_faq_schema_disallow_all_tags', 10, 1 );
function custom_faq_schema_disallow_all_tags( $tags ) {
// Return an empty string to disallow all HTML tags
return '';
}
You can check the detailed documentation here: https://www.kadencewp.com/help-center/docs/kadence-blocks/accordion-block/#removing-html-tags-from-the-faq-schema
Regards,
Archita
@architabasandrai20 Hi Archita,
I recently read about sanitizing tags, and I figured that’s what you’re doing. But the neither code you gave me nor the code on that documentation page solve the problem. Kadence is stripping the href attribute from the <a> tag in the Answer schema. I want to keep this attribute in the schema.
Hi @mesmer7,
Thanks for your patience.
We’ve submitted this to our dev team, as the filter is not working as expected even after implementation.
For now, please use the following custom code as a workaround:
add_filter( 'kadence_blocks_faq_schema_answer', 'custom_kadence_faq_schema_preserve_links', 10, 2 );
function custom_kadence_faq_schema_preserve_links( $answer, $block ) {
// Define the tags we want to allow (matching your list)
$allowed_tags_string = '<a><strong><br><h2><h3><h4><h5><ul><li><ol><p>';
// Define specifically which attributes we want to keep for which tags
$allowed_attributes = array(
'a' => array(
'href' => true,
'title' => true,
'target' => true,
),
// Add other tags here if you need specific attributes like 'class'
);
if ( isset( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) {
$new_answer = '';
foreach ( $block['innerBlocks'] as $inner_block ) {
$block_content = render_block( $inner_block );
// 1. Remove script and style tags
$block_content = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $block_content );
// 2. Use wp_kses to strip tags and attributes safely
// This is better than strip_tags + preg_replace because it's attribute-aware
$new_answer .= wp_kses( $block_content, $allowed_attributes + array_fill_keys(
explode( '>', str_replace( '<', '', $allowed_tags_string ) ),
array()
) );
}
return trim( $new_answer );
}
return $answer;
}
We’ll keep you posted as soon as we have an update from the team.
Regards,
Archita
@architabasandrai20
Thank you. This works.
Also ask your development team to research whether we should include <p> tags inside Answer schema. Might not need it if the Answer is only 1 sentence or 1 paragraph.
@architabasandrai20
Update: While the code you gave me worked for the schema, it caused a conflict with Rank Math sitemaps. Here is the discussion on the rank math support group.
https://wordpress.org/support/topic/the-site-map-no-longer-works-in-the-latest-version/#post-18873265
Hi @mesmer7,
Thanks for the update.
I’ll pass this along to our dev team for further review. In the meantime, could you please try adding the FAQ using Rank Math as a workaround?
Let me know how that goes.
Regards,
Archita
Rank Math’s FAQ schema is only available to Pro users. I use the free version. I’ll just have to wait for the theme update.
@architabasandrai20
Update, turns out the code you gave me works fine. The conflict was caused by a blank line after the closing ?> must have been a consequence of the way I copied it from the forum to my plugin.
But let me know here if the next update to the theme fixes the FAQ filter and I should delete this from my plugin.