grizzlypumpkin / statamic-json-ld
Configure and render JSON-LD schema for Statamic sites.
Package info
github.com/GrizzlyPumpkin/statamic-json-ld
Type:package
pkg:composer/grizzlypumpkin/statamic-json-ld
Requires
- php: ^8.3
- statamic/cms: ^6.0
Requires (Dev)
- laravel/pint: ^1.30
README
JSON-LD Statamic Addon
Provides an easy way to configure global Schema objects and per-collection objects with support for antlers to dynamically populate content.
Comes with a few built-in nodes, however, offers a custom node to allow for any schema object to be added.
Breadcrumbs are also supported and will be dynamically built based on your collection's configuration.
Installation
composer require grizzlypumpkin/statamic-json-ld
Usage
General Settings
The addon provides a range of options to configure how it behaves with your website:
- Enabled: Indicates if the addon is enabled or not, if disabled then no processing will be performed.
- Site URL: The URL of the site, if left blank then the app URL will be used instead.
- Include Breadcrumb Schema: If enabled the addon will calculate the breadcrumbs based on the collection or entry being viewed. See Breadcrumbs below for further details.
- Pretty Print JSON: If enabled the output JSON will be formatted to be more readable. Suggest turning this off once configured.
Global Schema
The schema defined in here will be rendered on every Statamic page. They have access to the global state via Antlers.
Some default nodes such as Organization, WebSite, CreativeWork, ProfessionalService, and LocalBusiness are supported. However, custom objects are also supported via the other schema type.
Collections
This provides a way to add additional collection specific schema markup. These will be added in addition to any global markup configured.
Once a collection has been selected, the schema is then the same as is available on the global, including custom.
Breadcrumbs
The breadcrumbs markup is supported and is automatically calculated based on the page being viewed. It relies on the Statamic Collection Mounting feature.
For example, if you have a collection of Blog Posts, you may choose to mount a Blog page to it. The breadcrumbs will then render as Home > Blog Page > Blog Post.
Rendering the markup
The addon provides a json_ld tag, which will output the markup generated. This would usually be placed in the <head> of your page.
{{ json_ld }}
Blade:
{{ Statamic::tag('json_ld') }}
The tag renders a single <script type="application/ld+json"> block containing a Schema.org @graph which has all of the computed markup objects.
Requirements
- PHP 8.3+
- Statamic 6