Hi everyone, this is partially a question but also some rubber ducking in hopes it’s useful for others.
Question
As a theme developer, it appears there is no way to programmatically toggle or modify the structured data emitted from ghost_head… correct?
Context
ghost_head emits some JSON-LD structured data already:
WebSiteArticle(apparently for post posts and pages)
The data contained within is set manually by the end user within Ghost Admin.
Why you might want to toggle/modify the ghost_head structured data
If you’re adding more structured data to your custom theme, it’s possible you’d like to have centralized control over all structured data, including WebSite and Article, in the code base.
For example, I have the following setup in my custom theme:
data/schema.jsonpartials/schema/<schema_object>.hbs(auto-generated JSON-LD scripts)scripts/build-schema.mjs
Before build-time, I call the script which builds the partials based on the JSON data. The templates then pick up these partials (the JSON-LD scripts) at build time.
However, I can’t control WebSite or Article at the code level because that’s coming from ghost_head.
Why you might not want to do this
If you have an end user who wants to control this stuff directly, the setup I loosely describe above will not work, since structured data edits would require code-level access.
I’m not trying to ship a downloadable theme in this case, and the single user I’m building the theme for doesn’t want this level of control.
(This is surely a solvable problem, but out of scope for this post and for my current needs.)
Workaround
The only workaround I’m aware of is to forego ghost_head entirely and write your own head instead.
That’s certainly a path one could take, but it’s too heavy-handed for my needs, so I’m sticking with ghost_head and living with the structured data that it provides “for free”.