Closed vkiranmaniya closed 3 years ago
I am interested in this too
@hajar-alpha I tried to find the workaround, but haven't found yet. I think we should implement it on our own. I'll make changes and create pull request soon.
@vkiranmaniya I was able to have a working option to what I think is the goal here by changing some of the config options. Not sure if it is a perfect solution.
In config/seotools.php
, I set title
, description
, and type
to false
, which prevents the default fields being output. This does however require specifying those fields where you would have made use of the defaults.
return [
'meta' => [
// ...
],
// ...
'json-ld' => [
'defaults' => [
'title' => false,
'description' => false,
'url' => false,
'type' => false,
'images' => [],
],
],
];
Then where I wanted to output the JsonLd, I used the addValue()
method, with the named @graph
:
(Stack overflow reference regarding @graph
HERE)
JsonLd::addValue('@graph', [
[
'@type' => 'Organization',
'name' => 'Org name',
// ...
],
[
'@type' => 'Website',
'name' => 'Website title',
// ...
],
]);
The output JSON:
{
"@context": "https:\/\/schema.org",
"@graph": [
{
"@type": "Organization",
"name": "Org name"
},
{
"@type": "Website",
"name": "Website title"
}
]
}
@vkiranmaniya I was able to have a working option to what I think is the goal here by changing some of the config options. Not sure if it is a perfect solution.
In
config/seotools.php
, I settitle
,description
, andtype
tofalse
, which prevents the default fields being output. This does however require specifying those fields where you would have made use of the defaults.return [ 'meta' => [ // ... ], // ... 'json-ld' => [ 'defaults' => [ 'title' => false, 'description' => false, 'url' => false, 'type' => false, 'images' => [], ], ], ];
Then where I wanted to output the JsonLd, I used the
addValue()
method, with the named@graph
:(Stack overflow reference regarding
@graph
HERE)JsonLd::addValue('@graph', [ [ '@type' => 'Organization', 'name' => 'Org name', // ... ], [ '@type' => 'Website', 'name' => 'Website title', // ... ], ]);
The output JSON:
{ "@context": "https:\/\/schema.org", "@graph": [ { "@type": "Organization", "name": "Org name" }, { "@type": "Website", "name": "Website title" } ] }
Yes, this may be a workaround, Let's try it out.
I was working also on complex jsonld, and it seems i made the same hacking as @justindantzer . This should be added in the readme as example for complex jsonld, so more people will know that this package is good and easy to use.
@BulgarianHealer @vkiranmaniya @vinicius73 you can used my PR(#229) for next code
$breadcumbsListItems = [
new JsonLd(['type' => 'ListItem', ...]),
new JsonLd(['type' => 'ListItem', ...]),
];
$breadcrumbList = new JsonLd([
'type' => 'BreadcrumbList',
'itemListElement' => $breadcumbsListItems,
]);
generating the JsonLD array having multiple JsonLD objects as given,
I want to generate the JsonLD array but didn't find the method to do it. Is it possible with this package or I need to modify? Let me know if there is no such method, I'll create a pull request for that.