JSON-LD
This page was created following a question by Angie Ratke on Twitter : https://twitter.com/AngieRadtke/status/1531649789951188993
Pages does JSON-LD out of the box. Remember the data()implementation in pages, which transform any array into json? You can use that to generate json-ld super easily.
Here is an example: https://github.com/johanjanssens/agrea.ph/blob/d59acc6e168684ff0ef43395a4e3155514faa00c/sites/agrea.ph/partials/navigation/breadcrumb.html.php
You could create a re-usable partial that handles this, then all you need to do is include it wherever you need it. Problem solved, for more static json-ld, you could use data files and then render the data file to json-ld.
It’s all very simple. No plugins or other things needed.
<? //Generate microdata
$segments = [];
$microdata = data([
"@context" => "https://schema.org",
"@type" => "BreadcrumbList",
'itemListElement' => []
]);
foreach ($route as $key => $segment)
{
$segments[] = $segment;
$microdata->itemListElement = [
"@type" => "ListItem",
"position" => $key + 1,
"name" => rtrim(page()->isCollection() ? ucfirst($segment) : page()->title, '.'),
"item" =>(string) url(route(implode('/', $segments)))
];
}
?>
<script data-inline type="application/ld+json">
<?= $microdata ?>
</script>