Skip to content

Commit e04b9be

Browse files
committed
Initial implementation of JSON-LD comment property
1 parent 44b6d69 commit e04b9be

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ If available, it will dynamically generate and include the following data inside
5656
"@context": "https://schema.org",
5757
"@type": "DiscussionForumPosting",
5858
"url": "...",
59+
"mainEntityOfPage": "...",
5960
"headline": "...",
6061
"description": "...",
6162
"text": "...",
@@ -77,7 +78,16 @@ If available, it will dynamically generate and include the following data inside
7778
"width": "...",
7879
"height": "..."
7980
}
80-
}
81+
},
82+
"comment": [{
83+
"@type": "Comment",
84+
"text": "...",
85+
"author": {
86+
"@type": "Person",
87+
"name": "...",
88+
"url": "..."
89+
}
90+
}]
8191
}
8292
</script>
8393
```

includes/helper.php

+26-3
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public function set_metadata($data = [])
180180
'@context' => 'https://schema.org',
181181
'@type' => 'DiscussionForumPosting',
182182
'url' => $default['url'],
183+
'mainEntityOfPage' => $default['url'],
183184
'headline' => '',
184185
'description' => $default['description'],
185186
'text' => $default['description'],
@@ -201,6 +202,17 @@ public function set_metadata($data = [])
201202
'width' => (int) $this->config['seo_metadata_json_ld_logo_width'],
202203
'height' => (int) $this->config['seo_metadata_json_ld_logo_height']
203204
]
205+
],
206+
'comment' => [
207+
[
208+
'@type' => 'Comment',
209+
'text' => '',
210+
'author' => [
211+
'@type' => 'Person',
212+
'name' => '',
213+
'url' => ''
214+
]
215+
]
204216
]
205217
]
206218
];
@@ -370,6 +382,15 @@ public function metadata_template_vars()
370382
unset($data['json_ld']['publisher']['logo']);
371383
}
372384

385+
// JSON-LD comment
386+
foreach ($data['json_ld']['comment'] as $key => $value)
387+
{
388+
if (empty($value['text']))
389+
{
390+
unset($data['json_ld']['comment'][$key]);
391+
}
392+
}
393+
373394
// Ignore disabled options
374395
foreach ($data as $key => $value)
375396
{
@@ -387,17 +408,19 @@ public function metadata_template_vars()
387408
// Assign data to template
388409
foreach ($data as $key => $value)
389410
{
411+
$type = strtoupper($key);
412+
390413
$this->template->assign_block_vars(
391414
'SEO_METADATA',
392415
[
393-
'NAME' => strtoupper($key),
416+
'NAME' => $type,
394417
]
395418
);
396419

397420
if ($key === 'json_ld')
398421
{
399422
$this->template->assign_block_vars(
400-
sprintf('SEO_METADATA.%s', strtoupper($key)),
423+
sprintf('SEO_METADATA.%s', $type),
401424
[
402425
'CONTENT' => json_encode($data[$key], JSON_UNESCAPED_SLASHES)
403426
]
@@ -409,7 +432,7 @@ public function metadata_template_vars()
409432
foreach ($value as $k => $v)
410433
{
411434
$this->template->assign_block_vars(
412-
sprintf('SEO_METADATA.%s', strtoupper($key)),
435+
sprintf('SEO_METADATA.%s', $type),
413436
[
414437
'PROPERTY' => $k,
415438
'CONTENT' => $v

0 commit comments

Comments
 (0)