Skip to content

Commit 4c658e5

Browse files
If structured data does not show, show the reason as an HTML comment
1 parent 95a1dc9 commit 4c658e5

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

classes/Visualizer/Module/Frontend.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ public function renderChart( $atts ) {
355355
* @access private
356356
*/
357357
private function addSchema( $id ) {
358+
// should we show informative errors as HTML comments?
359+
$show_errors = apply_filters( 'visualizer_schema_show_errors', true, $id );
360+
358361
$settings = get_post_meta( $id, Visualizer_Plugin::CF_SETTINGS, true );
359362
$title = '';
360363
if ( isset( $settings['title'] ) && ! empty( $settings['title'] ) ) {
@@ -365,6 +368,9 @@ private function addSchema( $id ) {
365368
}
366369
$title = apply_filters( 'visualizer_schema_name', $title, $id );
367370
if ( empty( $title ) ) {
371+
if ( $show_errors ) {
372+
return "<!-- Not showing structured data for chart $id because title is empty -->";
373+
}
368374
return '';
369375
}
370376

@@ -373,8 +379,18 @@ private function addSchema( $id ) {
373379
$desc = $settings['description'];
374380
}
375381
$desc = apply_filters( 'visualizer_schema_description', $desc, $id );
382+
if ( empty( $desc ) ) {
383+
if ( $show_errors ) {
384+
return "<!-- Not showing structured data for chart $id because description is empty -->";
385+
}
386+
return '';
387+
}
388+
376389
// descriptions below 50 chars are not allowed.
377-
if ( empty( $desc ) || strlen( $desc ) < 50 ) {
390+
if ( strlen( $desc ) < 50 ) {
391+
if ( $show_errors ) {
392+
return "<!-- Not showing structured data for chart $id because description is shorter than 50 characters -->";
393+
}
378394
return '';
379395
}
380396

0 commit comments

Comments
 (0)