You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Search: indexed content keeps the text of <script> elements (JSON-LD shows up in result excerpts) #54779
Impacted plugin: Jetpack Search (Instant Search), also via Jetpack on WordPress.com Atomic
What I expected: the content of <script> (and <style>) elements is left out of the indexed text, the way wp_strip_all_tags() drops it. Browsers never show it to readers.
What happened: the tags are stripped but the text inside them is indexed, so excerpts read like "author":[{"@type":"Person","name":"Ivan Illich","familyName":"Illich","givenName":"Ivan"}],"datePublished":"1974". On one site, 34 of 39 results for a common term had JSON in their highlights. The JSON matches query terms (names, titles), so it wins the highlight over the real prose. Because some of the indexed JSON only exists in raw post_content (it is rewritten at render time), the indexer appears to read raw post_content, not only post_content_filtered.
Why it matters: several citation, recipe, FAQ and review blocks store JSON-LD in the post (it's the documented way to ship static structured data without a render callback). Any of them makes search results unreadable.
Workaround we use: filtering jetpack_sync_before_enqueue_jetpack_sync_save_post, jetpack_sync_before_enqueue_jetpack_published_post and jetpack_sync_before_send_jetpack_full_sync_posts to remove <script> elements from post_content / post_content_filtered in the sync payload, then triggering a full posts sync.
Suggested fix: remove script, style, template and noscript elements, with their contents, before indexing content.
Steps to reproduce
Publish a post that has structured data stored in its content, e.g. a block whose saved markup ends with <script type="application/ld+json">{"@context":"https://schema.org","@type":"Book","name":"Tools for Conviviality","author":[{"@type":"Person","name":"Ivan Illich"}]}</script>
Let Jetpack Sync send the post, then search for a word that appears in the JSON (here "Illich").
Look at the result excerpt in Instant Search, or at highlight.content from GET https://public-api.wordpress.com/rest/v1.3/sites/{blog_id}/search?query=illich&highlight_fields[0]=content.
Site owner impact
Fewer than 20% of the total website/platform users
Severity
Minor
What other impact(s) does this issue have?
No response
If a workaround is available, please outline it here.
Activity