get_wpseo_schema(); if (empty($wpseo_schema)) return $schema_object; foreach ($wpseo_schema as $key => $value) { if (isset($schema_object[$key]) && !empty($schema_object[$key])) continue; $schema_object[$key] = $value; } return $schema_object; } // Override filter and get Yoast JSON data private function get_wpseo_schema():array { remove_filter('wpseo_json_ld_output', [$this, 'disable_wpseo'], 10, 2); ob_start(); do_action('wpseo_json_ld'); $html = ob_get_clean(); add_filter('wpseo_json_ld_output', [$this, 'disable_wpseo'], 10, 2); if (empty($html) || !preg_match_all('/]*>(.+)<\/script>/m', $html, $matches)) return []; $data = []; foreach ($matches[1] as $json_str) { $json_data = json_decode($json_str, true); if (!is_null($json_data) && is_array($json_data)) $data = array_merge($data, $json_data); } return $data; } } YoastSEO::instance();