exs/schema-breadcrumb-bundle
Symfony bundle that generates schema.org BreadcrumbList JSON-LD script tags from Twig. Pass an ordered array of breadcrumb items with name, URL, and optional image to the getJsonBreadcrumb() function to output valid structured data for search engines.
This bundle generates the <script> tag containing the json object required to define the BreadcrumbList object as defined by schema.org
Source: http://schema.org/BreadcrumbList
Add the bundle with composer :
$ composer require exs/schema-breadcrumb-bundle
Enable the bundle in the kernel :
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new EXS\SchemaBreadcrumbBundle\EXSSchemaBreadcrumbBundle(),
// ...
);
}
Example :
<!DOCTYPE html>
<html>
<head>
...
{{ getJsonBreadcrumb([
{
'name': 'Category One',
'url': 'http://www.test.tld/category-one',
'image': 'http://www.test.tld/images/category-one.png'
},
{
'name': 'Subcategory Two',
'url': 'http://www.test.tld/category-one/subcategory-two'
},
{
'name': 'Element Three',
'url': 'http://www.test.tld/category-one/subcategory-two/element-three'
}
]) }}
</head>
<body>
...
</body>
</html>
The order of the elements in the array is used to define the order of elements in the breadcrumb.
The example above will generate the ld+json tag as :
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "http://www.test.tld/category-one",
"name": "Category One",
"image": "http://www.test.tld/images/category-one.png"
}
},
{
"@type": "ListItem",
"position": 2,
"item": {
"@id": "http://www.test.tld/category-one/subcategory-two",
"name": "Subcategory Two"
}
},
{
"@type": "ListItem",
"position": 3,
"item": {
"@id": "http://www.test.tld/category-one/subcategory-two/element-three",
"name": "Element Three"
}
}
]
}
</script>
And will be interpreted by search engines as a breadcrumb like :
Category One > Subcategory Two > Element Three
How can I help you explore Laravel packages today?