@@ -231,23 +231,14 @@ private function extract_schema_from_html($html) {
231231 * Remove schema scripts from HTML content
232232 */
233233 private function remove_schema_from_html ($ html ) {
234- // First, remove entire head sections that contain our schema (in case feed has nested head tags)
235- // Match head tags that contain our schema script
236- $ head_with_schema_pattern = '/<head[^>]*>.*?<script[^>]*(?:id=[" \']jsonldSchema[" \'][^>]*type=[" \']application\/ld\+json[" \']|type=[" \']application\/ld\+json[" \'][^>]*id=[" \']jsonldSchema[" \'])[^>]*>.*?<\/script>.*?<\/head>/is ' ;
237- $ html = preg_replace ($ head_with_schema_pattern , '' , $ html );
238-
239- // Remove script tags with id="jsonldSchema" and type="application/ld+json"
240- // Handles attributes in any order and with single or double quotes
241- // This catches any remaining schema scripts (even outside head tags)
234+ // Remove schema script tags only — preserve other <head> contents (Glide CSS/JS, fonts)
242235 $ schema_script_pattern = '/<script[^>]*(?:id=[" \']jsonldSchema[" \'][^>]*type=[" \']application\/ld\+json[" \']|type=[" \']application\/ld\+json[" \'][^>]*id=[" \']jsonldSchema[" \'])[^>]*>.*?<\/script>/is ' ;
243236 $ html = preg_replace ($ schema_script_pattern , '' , $ html );
244-
245- // Also remove any stray/empty head tags that might be in the content
246- // Remove opening <head> tags
237+
238+ // Strip <head>/<\/head> wrapper tags but keep their contents
247239 $ html = preg_replace ('/<head[^>]*>/i ' , '' , $ html );
248- // Remove closing </head> tags
249240 $ html = preg_replace ('/<\/head>/i ' , '' , $ html );
250-
241+
251242 return $ html ;
252243 }
253244
@@ -300,7 +291,15 @@ public function process_output_buffer() {
300291 * Buffer callback - inject schemas into head section if they weren't output in wp_head
301292 */
302293 public function buffer_callback ($ buffer ) {
303- // Only process if we have schemas
294+ // Fix & entities that wptexturize injects inside <script> blocks
295+ // Applies to all feed types: reviewFeed, allReviewFeed, multiReviewFeed
296+ if (strpos ($ buffer , 'opioEntityId ' ) !== false ) {
297+ $ buffer = preg_replace_callback ('/<script\b[^>]*>(.*?)<\/script>/is ' , function ($ m ) {
298+ return str_replace ($ m [1 ], html_entity_decode ($ m [1 ], ENT_QUOTES | ENT_HTML5 , 'UTF-8 ' ), $ m [0 ]);
299+ }, $ buffer );
300+ }
301+
302+ // Only process schemas if we have them
304303 if (empty (self ::$ schema_scripts )) {
305304 return $ buffer ;
306305 }
0 commit comments