| @@ -150,8 +150,17 @@ | ||
| 150 | 150 | * @param array $items Non-empty FAQ items. |
| 151 | 151 | * @return void |
| 152 | 152 | */ |
| 153 | 153 | private function maybe_render_schema(array $settings, array $items): void { |
| 154 | + | |
| 155 | + // The Schema master switch and the matrix's per-content-type switch. | |
| 156 | + // This widget echoes its own <script> rather than registering with | |
| 157 | + // Schema_Graph, so gating the graph never reached it and it kept | |
| 158 | + // publishing with Schema switched off (#688). | |
| 159 | + if (class_exists('ThinkRank\\Frontend\\Schema_Graph') | |
| 160 | + && !\ThinkRank\Frontend\Schema_Graph::output_allowed()) { | |
| 161 | + return; | |
| 162 | + } | |
| 154 | 163 | if ('yes' !== ($settings['output_schema'] ?? 'yes')) { |
| 155 | 164 | return; |
| 156 | 165 | } |
| 157 | 166 | |
| @@ -158,8 +167,17 @@ | ||
| 158 | 167 | if (\Elementor\Plugin::$instance->editor->is_edit_mode()) { |
| 159 | 168 | return; |
| 160 | 169 | } |
| 161 | 170 | |
| 171 | + // The request's schema graph already merged this widget's questions into | |
| 172 | + // its single FAQPage; emitting again would duplicate it (#355). | |
| 173 | + if ( | |
| 174 | + class_exists('ThinkRank\\Frontend\\Schema_Graph') | |
| 175 | + && \ThinkRank\Frontend\Schema_Graph::instance()->absorbed_content_faq() | |
| 176 | + ) { | |
| 177 | + return; | |
| 178 | + } | |
| 179 | + | |
| 162 | 180 | $entities = []; |
| 163 | 181 | foreach ($items as $faq) { |
| 164 | 182 | $question = trim(wp_strip_all_tags((string) ($faq['question'] ?? ''))); |
| 165 | 183 | $answer = trim((string) ($faq['answer'] ?? '')); |
| @@ -186,8 +204,8 @@ | ||
| 186 | 204 | 'mainEntity' => $entities, |
| 187 | 205 | ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); |
| 188 | 206 | |
| 189 | 207 | if (false !== $json) { |
| 190 | - echo '<script type="application/ld+json">' . $json . '</script>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 208 | + echo '<script type="application/ld+json" data-thinkrank="faq">' . $json . '</script>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 191 | 209 | } |
| 192 | 210 | } |
| 193 | 211 | } |